opentelemetry-erlang-contrib/examples/basic_phoenix_ecto
Kai 44fd2a6871
Add Phoenix + Ecto example (#60)
* Boostrap Phoenix application from mix phx.new

* Add opentelemetry dependencies

* Setup opentelemetry for local env

* Setup Dockerfile, docker-compose and otel config

* Configure runtime config for exporter to export to otel collector in prod env

* Generate Posts HTML resources

* Add Release module to run migration in release

* Generate Users LiveView resource

* Add exporter configuration to export directly to external service

* Update README.md to include description and instructions

* Update README.md to include more details on exporting traces

* Fix otlp collector deprecated ports as suggested
2022-02-25 18:45:46 -07:00
..
assets Add Phoenix + Ecto example (#60) 2022-02-25 18:45:46 -07:00
config Add Phoenix + Ecto example (#60) 2022-02-25 18:45:46 -07:00
lib Add Phoenix + Ecto example (#60) 2022-02-25 18:45:46 -07:00
priv Add Phoenix + Ecto example (#60) 2022-02-25 18:45:46 -07:00
test Add Phoenix + Ecto example (#60) 2022-02-25 18:45:46 -07:00
.formatter.exs Add Phoenix + Ecto example (#60) 2022-02-25 18:45:46 -07:00
.gitignore Add Phoenix + Ecto example (#60) 2022-02-25 18:45:46 -07:00
Dockerfile Add Phoenix + Ecto example (#60) 2022-02-25 18:45:46 -07:00
README.md Add Phoenix + Ecto example (#60) 2022-02-25 18:45:46 -07:00
docker-compose.yaml Add Phoenix + Ecto example (#60) 2022-02-25 18:45:46 -07:00
mix.exs Add Phoenix + Ecto example (#60) 2022-02-25 18:45:46 -07:00
mix.lock Add Phoenix + Ecto example (#60) 2022-02-25 18:45:46 -07:00
otel-collector-config.yaml Add Phoenix + Ecto example (#60) 2022-02-25 18:45:46 -07:00

README.md

Phoenix + Ecto OpenTelemetry Example

This is a example repository that demo how to setup OpenTelemetry for Phoenix application with opentelemetry_phoenix and opentelemetry_ecto.

Here, we are using opentelemetry_exporter to export the traces to OpenTelemetry Collector. The collector in turn export the traces to Zipkin and Jaeger respectively.

Additionally, we also include the OpenTelemetry Collector and opentelemetry_exporter configuration to export the traces to external services like Honeycomb and Lightstep.

Getting Stated

By default, we only configure our OpenTelemetry collector to export traces to the local Zipkin and Jaeger.

Assuming you already have Docker and Docker Compose installed:

  1. Run docker-compose up to start the Phoenix application, PostgreSQL, OpenTelemetry Collector, Zipkin and Jaeger.
  2. Run migration on another terminal with:
    docker exec -it basic_phoenix_ecto_phoenix_1 /bin/bash ./bin/demo eval 'Demo.Release.migrate()'
    
  3. Browse to http://localhost:4000. Additionally, you can:
  1. Visit Zipkin at http://localhost:9411 and hit Run Query to look the the sample trace.
  2. Visit Jaeger UI at http://localhost:16686, select demo under Service and click Find Trace to look at the sample trace.
  3. Run docker-compose down to destroy the created resources.

Different ways to export traces

In general, there are 2 ways you can export your OpenTelemetry traces.

  • Export to OpenTelemetry Collector, which can then be configured to export to external services.

    Application --> OpenTelemetry Collector --> Zipkin
                                        |-----> Jaeger
    
  • Export directly to external services that accept OTLP protocol.

    Application --> External Service
    

For exporting to external services, be sure to checkout their documentation first. For example: