From fac809686208c3bb5adc488152b9944349f09f99 Mon Sep 17 00:00:00 2001 From: Daniel Baptista Dias Date: Tue, 16 Apr 2024 13:39:19 -0300 Subject: [PATCH] chore(examples): add datadog propagation example (#3797) * wip * wip * update readme * update readme --- examples/datadog-propagation/.gitignore | 57 +++ examples/datadog-propagation/.ruby-version | 1 + examples/datadog-propagation/README.md | 44 +++ .../collector/collector.config.step1.yaml | 33 ++ .../collector/collector.config.step2.yaml | 40 ++ .../collector/collector.config.step3.yaml | 40 ++ .../collector/collector.config.step4.yaml | 45 +++ .../docker-compose.step1.yaml | 63 +++ .../docker-compose.step2.yaml | 63 +++ .../docker-compose.step3.yaml | 64 +++ .../docker-compose.step4.yaml | 75 ++++ .../quick_start_api_datadog/.gitattributes | 7 + .../quick_start_api_datadog/.gitignore | 33 ++ .../quick_start_api_datadog/.ruby-version | 1 + .../quick_start_api_datadog/Dockerfile | 11 + .../quick_start_api_datadog/Gemfile | 51 +++ .../quick_start_api_datadog/Gemfile.lock | 370 ++++++++++++++++++ .../quick_start_api_datadog/Rakefile | 6 + .../app/controllers/application_controller.rb | 2 + .../app/controllers/concerns/.keep | 0 .../app/controllers/hello_controller.rb | 42 ++ .../app/models/application_record.rb | 3 + .../app/models/concerns/.keep | 0 .../app/views/layouts/mailer.html.erb | 13 + .../app/views/layouts/mailer.text.erb | 1 + .../quick_start_api_datadog/bin/bundle | 114 ++++++ .../quick_start_api_datadog/bin/rails | 4 + .../quick_start_api_datadog/bin/rake | 4 + .../quick_start_api_datadog/bin/setup | 33 ++ .../quick_start_api_datadog/config.ru | 6 + .../config/application.rb | 27 ++ .../quick_start_api_datadog/config/boot.rb | 4 + .../quick_start_api_datadog/config/cable.yml | 10 + .../config/credentials.yml.enc | 1 + .../config/database.yml | 25 ++ .../config/environment.rb | 5 + .../config/environments/development.rb | 75 ++++ .../config/environments/production.rb | 95 +++++ .../config/environments/test.rb | 60 +++ .../config/initializers/cors.rb | 16 + .../config/initializers/datadog.rb | 39 ++ .../initializers/filter_parameter_logging.rb | 8 + .../config/initializers/inflections.rb | 16 + .../config/locales/en.yml | 33 ++ .../quick_start_api_datadog/config/puma.rb | 43 ++ .../quick_start_api_datadog/config/routes.rb | 5 + .../config/storage.yml | 34 ++ .../quick_start_api_datadog/db/seeds.rb | 7 + .../quick_start_api_otel/.gitattributes | 7 + .../quick_start_api_otel/.gitignore | 33 ++ .../quick_start_api_otel/.ruby-version | 1 + .../quick_start_api_otel/Dockerfile | 11 + .../quick_start_api_otel/Gemfile | 53 +++ .../quick_start_api_otel/Gemfile.lock | 370 ++++++++++++++++++ .../quick_start_api_otel/Rakefile | 6 + .../app/controllers/application_controller.rb | 2 + .../app/controllers/concerns/.keep | 0 .../app/controllers/hello_controller.rb | 42 ++ .../app/models/application_record.rb | 3 + .../app/models/concerns/.keep | 0 .../app/views/layouts/mailer.html.erb | 13 + .../app/views/layouts/mailer.text.erb | 1 + .../quick_start_api_otel/bin/bundle | 114 ++++++ .../quick_start_api_otel/bin/rails | 4 + .../quick_start_api_otel/bin/rake | 4 + .../quick_start_api_otel/bin/setup | 33 ++ .../quick_start_api_otel/config.ru | 6 + .../config/application.rb | 27 ++ .../quick_start_api_otel/config/boot.rb | 4 + .../quick_start_api_otel/config/cable.yml | 10 + .../config/credentials.yml.enc | 1 + .../quick_start_api_otel/config/database.yml | 25 ++ .../config/environment.rb | 5 + .../config/environments/development.rb | 75 ++++ .../config/environments/production.rb | 95 +++++ .../config/environments/test.rb | 60 +++ .../config/initializers/cors.rb | 16 + .../initializers/filter_parameter_logging.rb | 8 + .../config/initializers/inflections.rb | 16 + .../config/initializers/open_telemetry.rb | 8 + .../config/locales/en.yml | 33 ++ .../quick_start_api_otel/config/puma.rb | 43 ++ .../quick_start_api_otel/config/routes.rb | 5 + .../quick_start_api_otel/config/storage.yml | 34 ++ .../quick_start_api_otel/db/seeds.rb | 7 + ...nted_api_to_otel_sdk_instrumented_api.yaml | 12 + ...ented_api_to_datadog_instrumented_api.yaml | 12 + 87 files changed, 2928 insertions(+) create mode 100644 examples/datadog-propagation/.gitignore create mode 100644 examples/datadog-propagation/.ruby-version create mode 100644 examples/datadog-propagation/README.md create mode 100644 examples/datadog-propagation/collector/collector.config.step1.yaml create mode 100644 examples/datadog-propagation/collector/collector.config.step2.yaml create mode 100644 examples/datadog-propagation/collector/collector.config.step3.yaml create mode 100644 examples/datadog-propagation/collector/collector.config.step4.yaml create mode 100644 examples/datadog-propagation/docker-compose.step1.yaml create mode 100644 examples/datadog-propagation/docker-compose.step2.yaml create mode 100644 examples/datadog-propagation/docker-compose.step3.yaml create mode 100644 examples/datadog-propagation/docker-compose.step4.yaml create mode 100644 examples/datadog-propagation/quick_start_api_datadog/.gitattributes create mode 100644 examples/datadog-propagation/quick_start_api_datadog/.gitignore create mode 100644 examples/datadog-propagation/quick_start_api_datadog/.ruby-version create mode 100644 examples/datadog-propagation/quick_start_api_datadog/Dockerfile create mode 100644 examples/datadog-propagation/quick_start_api_datadog/Gemfile create mode 100644 examples/datadog-propagation/quick_start_api_datadog/Gemfile.lock create mode 100644 examples/datadog-propagation/quick_start_api_datadog/Rakefile create mode 100644 examples/datadog-propagation/quick_start_api_datadog/app/controllers/application_controller.rb create mode 100644 examples/datadog-propagation/quick_start_api_datadog/app/controllers/concerns/.keep create mode 100644 examples/datadog-propagation/quick_start_api_datadog/app/controllers/hello_controller.rb create mode 100644 examples/datadog-propagation/quick_start_api_datadog/app/models/application_record.rb create mode 100644 examples/datadog-propagation/quick_start_api_datadog/app/models/concerns/.keep create mode 100644 examples/datadog-propagation/quick_start_api_datadog/app/views/layouts/mailer.html.erb create mode 100644 examples/datadog-propagation/quick_start_api_datadog/app/views/layouts/mailer.text.erb create mode 100755 examples/datadog-propagation/quick_start_api_datadog/bin/bundle create mode 100755 examples/datadog-propagation/quick_start_api_datadog/bin/rails create mode 100755 examples/datadog-propagation/quick_start_api_datadog/bin/rake create mode 100755 examples/datadog-propagation/quick_start_api_datadog/bin/setup create mode 100644 examples/datadog-propagation/quick_start_api_datadog/config.ru create mode 100644 examples/datadog-propagation/quick_start_api_datadog/config/application.rb create mode 100644 examples/datadog-propagation/quick_start_api_datadog/config/boot.rb create mode 100644 examples/datadog-propagation/quick_start_api_datadog/config/cable.yml create mode 100644 examples/datadog-propagation/quick_start_api_datadog/config/credentials.yml.enc create mode 100644 examples/datadog-propagation/quick_start_api_datadog/config/database.yml create mode 100644 examples/datadog-propagation/quick_start_api_datadog/config/environment.rb create mode 100644 examples/datadog-propagation/quick_start_api_datadog/config/environments/development.rb create mode 100644 examples/datadog-propagation/quick_start_api_datadog/config/environments/production.rb create mode 100644 examples/datadog-propagation/quick_start_api_datadog/config/environments/test.rb create mode 100644 examples/datadog-propagation/quick_start_api_datadog/config/initializers/cors.rb create mode 100644 examples/datadog-propagation/quick_start_api_datadog/config/initializers/datadog.rb create mode 100644 examples/datadog-propagation/quick_start_api_datadog/config/initializers/filter_parameter_logging.rb create mode 100644 examples/datadog-propagation/quick_start_api_datadog/config/initializers/inflections.rb create mode 100644 examples/datadog-propagation/quick_start_api_datadog/config/locales/en.yml create mode 100644 examples/datadog-propagation/quick_start_api_datadog/config/puma.rb create mode 100644 examples/datadog-propagation/quick_start_api_datadog/config/routes.rb create mode 100644 examples/datadog-propagation/quick_start_api_datadog/config/storage.yml create mode 100644 examples/datadog-propagation/quick_start_api_datadog/db/seeds.rb create mode 100644 examples/datadog-propagation/quick_start_api_otel/.gitattributes create mode 100644 examples/datadog-propagation/quick_start_api_otel/.gitignore create mode 100644 examples/datadog-propagation/quick_start_api_otel/.ruby-version create mode 100644 examples/datadog-propagation/quick_start_api_otel/Dockerfile create mode 100644 examples/datadog-propagation/quick_start_api_otel/Gemfile create mode 100644 examples/datadog-propagation/quick_start_api_otel/Gemfile.lock create mode 100644 examples/datadog-propagation/quick_start_api_otel/Rakefile create mode 100644 examples/datadog-propagation/quick_start_api_otel/app/controllers/application_controller.rb create mode 100644 examples/datadog-propagation/quick_start_api_otel/app/controllers/concerns/.keep create mode 100644 examples/datadog-propagation/quick_start_api_otel/app/controllers/hello_controller.rb create mode 100644 examples/datadog-propagation/quick_start_api_otel/app/models/application_record.rb create mode 100644 examples/datadog-propagation/quick_start_api_otel/app/models/concerns/.keep create mode 100644 examples/datadog-propagation/quick_start_api_otel/app/views/layouts/mailer.html.erb create mode 100644 examples/datadog-propagation/quick_start_api_otel/app/views/layouts/mailer.text.erb create mode 100755 examples/datadog-propagation/quick_start_api_otel/bin/bundle create mode 100755 examples/datadog-propagation/quick_start_api_otel/bin/rails create mode 100755 examples/datadog-propagation/quick_start_api_otel/bin/rake create mode 100755 examples/datadog-propagation/quick_start_api_otel/bin/setup create mode 100644 examples/datadog-propagation/quick_start_api_otel/config.ru create mode 100644 examples/datadog-propagation/quick_start_api_otel/config/application.rb create mode 100644 examples/datadog-propagation/quick_start_api_otel/config/boot.rb create mode 100644 examples/datadog-propagation/quick_start_api_otel/config/cable.yml create mode 100644 examples/datadog-propagation/quick_start_api_otel/config/credentials.yml.enc create mode 100644 examples/datadog-propagation/quick_start_api_otel/config/database.yml create mode 100644 examples/datadog-propagation/quick_start_api_otel/config/environment.rb create mode 100644 examples/datadog-propagation/quick_start_api_otel/config/environments/development.rb create mode 100644 examples/datadog-propagation/quick_start_api_otel/config/environments/production.rb create mode 100644 examples/datadog-propagation/quick_start_api_otel/config/environments/test.rb create mode 100644 examples/datadog-propagation/quick_start_api_otel/config/initializers/cors.rb create mode 100644 examples/datadog-propagation/quick_start_api_otel/config/initializers/filter_parameter_logging.rb create mode 100644 examples/datadog-propagation/quick_start_api_otel/config/initializers/inflections.rb create mode 100644 examples/datadog-propagation/quick_start_api_otel/config/initializers/open_telemetry.rb create mode 100644 examples/datadog-propagation/quick_start_api_otel/config/locales/en.yml create mode 100644 examples/datadog-propagation/quick_start_api_otel/config/puma.rb create mode 100644 examples/datadog-propagation/quick_start_api_otel/config/routes.rb create mode 100644 examples/datadog-propagation/quick_start_api_otel/config/storage.yml create mode 100644 examples/datadog-propagation/quick_start_api_otel/db/seeds.rb create mode 100644 examples/datadog-propagation/tracebased-tests/datadog_instrumented_api_to_otel_sdk_instrumented_api.yaml create mode 100644 examples/datadog-propagation/tracebased-tests/otel_sdk_instrumented_api_to_datadog_instrumented_api.yaml diff --git a/examples/datadog-propagation/.gitignore b/examples/datadog-propagation/.gitignore new file mode 100644 index 0000000000..06378eabcf --- /dev/null +++ b/examples/datadog-propagation/.gitignore @@ -0,0 +1,57 @@ +.DS_Store +*.gem +*.rbc +/.config +/coverage/ +/InstalledFiles +/pkg/ +/spec/reports/ +/spec/examples.txt +/test/tmp/ +/test/version_tmp/ +/tmp/ + +# Used by dotenv library to load environment variables. +# .env + +# Ignore Byebug command history file. +.byebug_history + +## Specific to RubyMotion: +.dat* +.repl_history +build/ +*.bridgesupport +build-iPhoneOS/ +build-iPhoneSimulator/ + +## Specific to RubyMotion (use of CocoaPods): +# +# We recommend against adding the Pods directory to your .gitignore. However +# you should judge for yourself, the pros and cons are mentioned at: +# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control +# +# vendor/Pods/ + +## Documentation cache and generated files: +/.yardoc/ +/_yardoc/ +/doc/ +/rdoc/ + +## Environment normalization: +/.bundle/ +/vendor/bundle +/lib/bundler/man/ + +# for a library or gem, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# Gemfile.lock +# .ruby-version +# .ruby-gemset + +# unless supporting rvm < 1.11.0 or doing something fancy, ignore this: +.rvmrc + +# Used by RuboCop. Remote config files pulled in from inherit_from directive. +# .rubocop-https?--* diff --git a/examples/datadog-propagation/.ruby-version b/examples/datadog-propagation/.ruby-version new file mode 100644 index 0000000000..ef538c2810 --- /dev/null +++ b/examples/datadog-propagation/.ruby-version @@ -0,0 +1 @@ +3.1.2 diff --git a/examples/datadog-propagation/README.md b/examples/datadog-propagation/README.md new file mode 100644 index 0000000000..a917be0262 --- /dev/null +++ b/examples/datadog-propagation/README.md @@ -0,0 +1,44 @@ +# Context Propagation between Rails API instrumented with ddtrace and OTel SDK + +This repository shows an example of how to propagate context between `ddtrace` instrumented APIs and OTel SDK APIs. + +## The problem + +Datadog represents its TraceIds as an uint64, while OTel SDK represents it as a 128-bit hexadecimal string, causing some issues with Trace propagation when you use OTel Collector's `datadog` receiver along an external Tracing Backend that isn't Datadog. + +## Solution + +Datadog can build an entire TraceID using a tag called `_dd.p.tid` as the upper part of a TraceId and its own TraceId in hexadecimal format as the lower part. To use this data to generate the OTel TraceID we changed how our `ddtrace` sends Traces to send the `_dd.p.tid` tag in all spans (normally it sends this attribute only for the first trace span) and changed our OTel Collector to have a `transform` processor, that will grab the upper and lower part of the TraceID and will reconstruct it. + +### How to test it + +There are 4 `docker-compose` files, showing each stage of the solution. Each file has two Rails APIs defined, one Datadog-instrumented and another OTelSDK-instrumented, one OTel Collector configured to receive traces from OTLP and Datadog and a Jaeger to ingest the data and show it. + +After starting the APIs with one of the docker compose files, you can test the APIs locally by executing one of the following `curl` commands and checking on Jaeger on `http://localhost:16686/`: +```sh +# Test API call from OTelSDK-instrumented API to Datadog-instrumented API +curl http://localhost:8080/remotehello + +# Test API call from OTelSDK-instrumented API to Datadog-instrumented API +curl http://localhost:8081/remotehello +``` + +The first file, `docker-compose.step1.yaml`, shows the propagation problem happening. When you call any of the `curl` requests, you should see two split traces on Jaeger, one for each API. You can run it with: +```sh +docker compose -f ./docker-compose.step1.yaml up +``` + +The second file, `docker-compose.step2.yaml`, runs the OTel Collector with a `transform` processor that fixes the `TraceID` for spans that have `_dd.p.tid` attribute. After calling a `curl` request, you should see one trace that has the first span of the Datadog-instrumented API call along with all spans emitted by the OTelSDK-instrumented API, and another trace with Datadog-instrumented API that doesn't have `_dd.p.tid` attribute. You can run it with: +```sh +docker compose -f ./docker-compose.step2.yaml up +``` + +The third file, `docker-compose.step3.yaml`, does a patch on `ddtrace` to inject `_dd.p.tid` attribute on each span instrumented by `ddtrace`, also renaming `_dd.p.tid` attribute to `propagation.upper_trace_id`. This version runs the OTel Collector with a `transform` processor that fixes the `TraceID` for spans that have `propagation.upper_trace_id` attribute. After calling a `curl` request, you should see just one trace with all spans emitted by the OTelSDK-instrumented API and Datadog-instrumented API. You can run it with: +```sh +docker compose -f ./docker-compose.step3.yaml up +``` + +The last file, `docker-compose.step4.yaml`, adds Tracetest to the stack to allow us to test the traces and guarantee that everything is working right. You can run it with: +```sh +TRACETEST_API_KEY=your-api-key docker compose -f ./docker-compose.step4.yaml up +``` diff --git a/examples/datadog-propagation/collector/collector.config.step1.yaml b/examples/datadog-propagation/collector/collector.config.step1.yaml new file mode 100644 index 0000000000..c8d67c40ce --- /dev/null +++ b/examples/datadog-propagation/collector/collector.config.step1.yaml @@ -0,0 +1,33 @@ +receivers: + otlp: + protocols: + grpc: + http: + + datadog: + endpoint: 0.0.0.0:8126 + read_timeout: 60s + +processors: + probabilistic_sampler: + hash_seed: 22 + sampling_percentage: 100 + + batch: + timeout: 100ms + +exporters: + debug: + verbosity: detailed + + otlp/jaeger: + endpoint: jaeger:4317 + tls: + insecure: true + +service: + pipelines: + traces: + receivers: [otlp, datadog] + processors: [probabilistic_sampler, batch] + exporters: [otlp/jaeger, debug] diff --git a/examples/datadog-propagation/collector/collector.config.step2.yaml b/examples/datadog-propagation/collector/collector.config.step2.yaml new file mode 100644 index 0000000000..6cc5d3cefe --- /dev/null +++ b/examples/datadog-propagation/collector/collector.config.step2.yaml @@ -0,0 +1,40 @@ +receivers: + otlp: + protocols: + grpc: + http: + + datadog: + endpoint: 0.0.0.0:8126 + read_timeout: 60s + +processors: + probabilistic_sampler: + hash_seed: 22 + sampling_percentage: 100 + batch: + timeout: 100ms + transform: + trace_statements: + - context: span + statements: + - set(cache["upper_trace_id"], attributes["_dd.p.tid"]) where attributes["_dd.p.tid"] != nil + - set(cache["lower_trace_id"], Substring(trace_id.string, 16, 16)) where cache["upper_trace_id"] != nil + - set(cache["combined_trace_id"], Concat([cache["upper_trace_id"], cache["lower_trace_id"]],"")) where cache["upper_trace_id"] != nil + - set(trace_id.string, cache["combined_trace_id"]) where cache["combined_trace_id"] != nil + +exporters: + debug: + verbosity: detailed + + otlp/jaeger: + endpoint: jaeger:4317 + tls: + insecure: true + +service: + pipelines: + traces: + receivers: [otlp, datadog] + processors: [transform, probabilistic_sampler, batch] + exporters: [otlp/jaeger, debug] diff --git a/examples/datadog-propagation/collector/collector.config.step3.yaml b/examples/datadog-propagation/collector/collector.config.step3.yaml new file mode 100644 index 0000000000..e484b776fc --- /dev/null +++ b/examples/datadog-propagation/collector/collector.config.step3.yaml @@ -0,0 +1,40 @@ +receivers: + otlp: + protocols: + grpc: + http: + + datadog: + endpoint: 0.0.0.0:8126 + read_timeout: 60s + +processors: + probabilistic_sampler: + hash_seed: 22 + sampling_percentage: 100 + batch: + timeout: 100ms + transform: + trace_statements: + - context: span + statements: + - set(cache["upper_trace_id"], attributes["propagation.upper_trace_id"]) where attributes["propagation.upper_trace_id"] != nil + - set(cache["lower_trace_id"], Substring(trace_id.string, 16, 16)) where cache["upper_trace_id"] != nil + - set(cache["combined_trace_id"], Concat([cache["upper_trace_id"], cache["lower_trace_id"]],"")) where cache["upper_trace_id"] != nil + - set(trace_id.string, cache["combined_trace_id"]) where cache["combined_trace_id"] != nil + +exporters: + debug: + verbosity: detailed + + otlp/jaeger: + endpoint: jaeger:4317 + tls: + insecure: true + +service: + pipelines: + traces: + receivers: [otlp, datadog] + processors: [transform, probabilistic_sampler, batch] + exporters: [otlp/jaeger, debug] diff --git a/examples/datadog-propagation/collector/collector.config.step4.yaml b/examples/datadog-propagation/collector/collector.config.step4.yaml new file mode 100644 index 0000000000..4426b14837 --- /dev/null +++ b/examples/datadog-propagation/collector/collector.config.step4.yaml @@ -0,0 +1,45 @@ +receivers: + otlp: + protocols: + grpc: + http: + + datadog: + endpoint: 0.0.0.0:8126 + read_timeout: 60s + +processors: + probabilistic_sampler: + hash_seed: 22 + sampling_percentage: 100 + batch: + timeout: 100ms + transform: + trace_statements: + - context: span + statements: + - set(cache["upper_trace_id"], attributes["propagation.upper_trace_id"]) where attributes["propagation.upper_trace_id"] != nil + - set(cache["lower_trace_id"], Substring(trace_id.string, 16, 16)) where cache["upper_trace_id"] != nil + - set(cache["combined_trace_id"], Concat([cache["upper_trace_id"], cache["lower_trace_id"]],"")) where cache["upper_trace_id"] != nil + - set(trace_id.string, cache["combined_trace_id"]) where cache["combined_trace_id"] != nil + +exporters: + debug: + verbosity: detailed + + otlp/tracetest: + endpoint: tracetest-agent:4317 + tls: + insecure: true + + otlp/jaeger: + endpoint: jaeger:4317 + tls: + insecure: true + +service: + pipelines: + traces: + receivers: [otlp, datadog] + processors: [transform, probabilistic_sampler, batch] + exporters: [otlp/tracetest, otlp/jaeger, debug] diff --git a/examples/datadog-propagation/docker-compose.step1.yaml b/examples/datadog-propagation/docker-compose.step1.yaml new file mode 100644 index 0000000000..8567245065 --- /dev/null +++ b/examples/datadog-propagation/docker-compose.step1.yaml @@ -0,0 +1,63 @@ +version: '3' +services: + ######################### + # Instrumented APIs + ######################### + + api-otel: + image: quick-start-api-otel + build: ./quick_start_api_otel/. + platform: linux/amd64 + extra_hosts: + - "host.docker.internal:host-gateway" + ports: + - 8080:8080 + environment: + OTEL_EXPORTER_OTLP_TRACES_ENDPOINT: http://otel-collector:4318/v1/traces + RAILS_ENV: development + REMOTE_API: api-datadog + SERVICE_NAME: quick-start-api-otel + TELEMETRY_TYPE: otel + + api-datadog: + image: quick-start-api-datadog + build: ./quick_start_api_datadog/. + platform: linux/amd64 + extra_hosts: + - "host.docker.internal:host-gateway" + ports: + - 8081:8080 + environment: + DD_AGENT_HOST: otel-collector + DD_ENV: docker + DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED: true + DD_TRACE_AGENT_URL: http://otel-collector:8126 + DD_TRACE_PROPAGATION_STYLE: tracecontext + RAILS_ENV: development + REMOTE_API: api-otel + SERVICE_NAME: quick-start-api-datadog + TELEMETRY_TYPE: datadog + + ######################### + # Observability stack + ######################### + + otel-collector: + image: otel/opentelemetry-collector-contrib:0.97.0 + command: + - "--config" + - "/otel-local-config.yaml" + volumes: + - ./collector/collector.config.step1.yaml:/otel-local-config.yaml + + jaeger: + image: jaegertracing/all-in-one:latest + restart: unless-stopped + healthcheck: + test: ["CMD", "wget", "--spider", "localhost:16686"] + interval: 1s + timeout: 3s + retries: 60 + ports: + - 16685:16685 + - 16686:16686 diff --git a/examples/datadog-propagation/docker-compose.step2.yaml b/examples/datadog-propagation/docker-compose.step2.yaml new file mode 100644 index 0000000000..91d9c38d3c --- /dev/null +++ b/examples/datadog-propagation/docker-compose.step2.yaml @@ -0,0 +1,63 @@ +version: '3' +services: + ######################### + # Instrumented APIs + ######################### + + api-otel: + image: quick-start-api-otel + build: ./quick_start_api_otel/. + platform: linux/amd64 + extra_hosts: + - "host.docker.internal:host-gateway" + ports: + - 8080:8080 + environment: + OTEL_EXPORTER_OTLP_TRACES_ENDPOINT: http://otel-collector:4318/v1/traces + RAILS_ENV: development + REMOTE_API: api-datadog + SERVICE_NAME: quick-start-api-otel + TELEMETRY_TYPE: otel + + api-datadog: + image: quick-start-api-datadog + build: ./quick_start_api_datadog/. + platform: linux/amd64 + extra_hosts: + - "host.docker.internal:host-gateway" + ports: + - 8081:8080 + environment: + DD_AGENT_HOST: otel-collector + DD_ENV: docker + DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED: true + DD_TRACE_AGENT_URL: http://otel-collector:8126 + DD_TRACE_PROPAGATION_STYLE: tracecontext + RAILS_ENV: development + REMOTE_API: api-otel + SERVICE_NAME: quick-start-api-datadog + TELEMETRY_TYPE: datadog + + ######################### + # Observability stack + ######################### + + otel-collector: + image: otel/opentelemetry-collector-contrib:0.97.0 + command: + - "--config" + - "/otel-local-config.yaml" + volumes: + - ./collector/collector.config.step2.yaml:/otel-local-config.yaml + + jaeger: + image: jaegertracing/all-in-one:latest + restart: unless-stopped + healthcheck: + test: ["CMD", "wget", "--spider", "localhost:16686"] + interval: 1s + timeout: 3s + retries: 60 + ports: + - 16685:16685 + - 16686:16686 diff --git a/examples/datadog-propagation/docker-compose.step3.yaml b/examples/datadog-propagation/docker-compose.step3.yaml new file mode 100644 index 0000000000..2515e1ccfa --- /dev/null +++ b/examples/datadog-propagation/docker-compose.step3.yaml @@ -0,0 +1,64 @@ +version: '3' +services: + ######################### + # Instrumented APIs + ######################### + + api-otel: + image: quick-start-api-otel + build: ./quick_start_api_otel/. + platform: linux/amd64 + extra_hosts: + - "host.docker.internal:host-gateway" + ports: + - 8080:8080 + environment: + OTEL_EXPORTER_OTLP_TRACES_ENDPOINT: http://otel-collector:4318/v1/traces + RAILS_ENV: development + REMOTE_API: api-datadog + SERVICE_NAME: quick-start-api-otel + TELEMETRY_TYPE: otel + + api-datadog: + image: quick-start-api-datadog + build: ./quick_start_api_datadog/. + platform: linux/amd64 + extra_hosts: + - "host.docker.internal:host-gateway" + ports: + - 8081:8080 + environment: + DD_AGENT_HOST: otel-collector + DD_ENV: docker + DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED: true + DD_TRACE_AGENT_URL: http://otel-collector:8126 + DD_TRACE_PROPAGATION_STYLE: tracecontext + INJECT_UPPER_TRACE_ID: true + RAILS_ENV: development + REMOTE_API: api-otel + SERVICE_NAME: quick-start-api-datadog + TELEMETRY_TYPE: datadog + + ######################### + # Observability stack + ######################### + + otel-collector: + image: otel/opentelemetry-collector-contrib:0.97.0 + command: + - "--config" + - "/otel-local-config.yaml" + volumes: + - ./collector/collector.config.step3.yaml:/otel-local-config.yaml + + jaeger: + image: jaegertracing/all-in-one:latest + restart: unless-stopped + healthcheck: + test: ["CMD", "wget", "--spider", "localhost:16686"] + interval: 1s + timeout: 3s + retries: 60 + ports: + - 16685:16685 + - 16686:16686 diff --git a/examples/datadog-propagation/docker-compose.step4.yaml b/examples/datadog-propagation/docker-compose.step4.yaml new file mode 100644 index 0000000000..4b3c28dfd6 --- /dev/null +++ b/examples/datadog-propagation/docker-compose.step4.yaml @@ -0,0 +1,75 @@ +version: '3' +services: + ######################### + # Instrumented APIs + ######################### + + api-otel: + image: quick-start-api-otel + build: ./quick_start_api_otel/. + platform: linux/amd64 + extra_hosts: + - "host.docker.internal:host-gateway" + ports: + - 8080:8080 + environment: + OTEL_EXPORTER_OTLP_TRACES_ENDPOINT: http://otel-collector:4318/v1/traces + RAILS_ENV: development + REMOTE_API: api-datadog + SERVICE_NAME: quick-start-api-otel + TELEMETRY_TYPE: otel + + api-datadog: + image: quick-start-api-datadog + build: ./quick_start_api_datadog/. + platform: linux/amd64 + extra_hosts: + - "host.docker.internal:host-gateway" + ports: + - 8081:8080 + environment: + DD_AGENT_HOST: otel-collector + DD_ENV: docker + DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED: true + DD_TRACE_AGENT_URL: http://otel-collector:8126 + DD_TRACE_PROPAGATION_STYLE: tracecontext + INJECT_UPPER_TRACE_ID: true + RAILS_ENV: development + REMOTE_API: api-otel + SERVICE_NAME: quick-start-api-datadog + TELEMETRY_TYPE: datadog + + ######################### + # Observability stack + ######################### + + otel-collector: + image: otel/opentelemetry-collector-contrib:0.97.0 + command: + - "--config" + - "/otel-local-config.yaml" + volumes: + - ./collector/collector.config.step4.yaml:/otel-local-config.yaml + + jaeger: + image: jaegertracing/all-in-one:latest + restart: unless-stopped + healthcheck: + test: ["CMD", "wget", "--spider", "localhost:16686"] + interval: 1s + timeout: 3s + retries: 60 + ports: + - 16685:16685 + - 16686:16686 + + ######################### + # Testing stack + ######################### + + tracetest-agent: + image: kubeshop/tracetest-agent:latest + environment: + TRACETEST_API_KEY: ${TRACETEST_API_KEY} + TRACETEST_DEV: ${TRACETEST_DEV} + TRACETEST_MODE: verbose diff --git a/examples/datadog-propagation/quick_start_api_datadog/.gitattributes b/examples/datadog-propagation/quick_start_api_datadog/.gitattributes new file mode 100644 index 0000000000..31eeee0b6a --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_datadog/.gitattributes @@ -0,0 +1,7 @@ +# See https://git-scm.com/docs/gitattributes for more about git attribute files. + +# Mark the database schema as having been generated. +db/schema.rb linguist-generated + +# Mark any vendored files as having been vendored. +vendor/* linguist-vendored diff --git a/examples/datadog-propagation/quick_start_api_datadog/.gitignore b/examples/datadog-propagation/quick_start_api_datadog/.gitignore new file mode 100644 index 0000000000..12439e5858 --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_datadog/.gitignore @@ -0,0 +1,33 @@ +# See https://help.github.com/articles/ignoring-files for more about ignoring files. +# +# If you find yourself ignoring temporary files generated by your text editor +# or operating system, you probably want to add a global ignore instead: +# git config --global core.excludesfile '~/.gitignore_global' + +# Ignore bundler config. +/.bundle + +# Ignore the default SQLite database. +/db/*.sqlite3 +/db/*.sqlite3-* + +# Ignore all logfiles and tempfiles. +/log/* +/tmp/* +!/log/.keep +!/tmp/.keep + +# Ignore pidfiles, but keep the directory. +/tmp/pids/* +!/tmp/pids/ +!/tmp/pids/.keep + +# Ignore uploaded files in development. +/storage/* +!/storage/.keep +/tmp/storage/* +!/tmp/storage/ +!/tmp/storage/.keep + +# Ignore master key for decrypting credentials and more. +/config/master.key diff --git a/examples/datadog-propagation/quick_start_api_datadog/.ruby-version b/examples/datadog-propagation/quick_start_api_datadog/.ruby-version new file mode 100644 index 0000000000..7bde84d06c --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_datadog/.ruby-version @@ -0,0 +1 @@ +ruby-3.1.2 diff --git a/examples/datadog-propagation/quick_start_api_datadog/Dockerfile b/examples/datadog-propagation/quick_start_api_datadog/Dockerfile new file mode 100644 index 0000000000..9658e51a8c --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_datadog/Dockerfile @@ -0,0 +1,11 @@ +FROM ruby:3.1.2-alpine +WORKDIR /usr/src/app + +COPY Gemfile Gemfile.lock . +RUN apk update && apk add make gcc musl-dev && bundle install + +COPY . . +RUN chmod 666 ./Gemfile.lock +EXPOSE 8080 + +CMD [ "bundle", "exec", "rails", "server", "--port", "8080", "--binding", "0.0.0.0" ] diff --git a/examples/datadog-propagation/quick_start_api_datadog/Gemfile b/examples/datadog-propagation/quick_start_api_datadog/Gemfile new file mode 100644 index 0000000000..d8c0f31a62 --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_datadog/Gemfile @@ -0,0 +1,51 @@ +source "https://rubygems.org" +git_source(:github) { |repo| "https://github.com/#{repo}.git" } + +ruby "3.1.2" + +# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main" +gem "rails", "~> 7.0.4", ">= 7.0.4.3" + +# Use sqlite3 as the database for Active Record +gem "sqlite3", "~> 1.4" + +# Use the Puma web server [https://github.com/puma/puma] +gem "puma", "~> 5.6" + +# Build JSON APIs with ease [https://github.com/rails/jbuilder] +# gem "jbuilder" + +# Use Redis adapter to run Action Cable in production +# gem "redis", "~> 4.0" + +# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis] +# gem "kredis" + +# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword] +# gem "bcrypt", "~> 3.1.7" + +# Windows does not include zoneinfo files, so bundle the tzinfo-data gem +gem "tzinfo-data" + +# Adding support for Datadog +gem "ddtrace", require: "ddtrace/auto_instrument" + +# Reduces boot times through caching; required in config/boot.rb +gem "bootsnap", require: false + +# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images] +# gem "image_processing", "~> 1.2" + +# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible +# gem "rack-cors" + +group :development, :test do + # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem + gem "debug", platforms: %i[ mri mingw x64_mingw ] +end + +group :development do + # Speed up commands on slow machines / big apps [https://github.com/rails/spring] + # gem "spring" +end + diff --git a/examples/datadog-propagation/quick_start_api_datadog/Gemfile.lock b/examples/datadog-propagation/quick_start_api_datadog/Gemfile.lock new file mode 100644 index 0000000000..dd40ca97d4 --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_datadog/Gemfile.lock @@ -0,0 +1,370 @@ +GEM + remote: https://rubygems.org/ + specs: + actioncable (7.0.4.3) + actionpack (= 7.0.4.3) + activesupport (= 7.0.4.3) + nio4r (~> 2.0) + websocket-driver (>= 0.6.1) + actionmailbox (7.0.4.3) + actionpack (= 7.0.4.3) + activejob (= 7.0.4.3) + activerecord (= 7.0.4.3) + activestorage (= 7.0.4.3) + activesupport (= 7.0.4.3) + mail (>= 2.7.1) + net-imap + net-pop + net-smtp + actionmailer (7.0.4.3) + actionpack (= 7.0.4.3) + actionview (= 7.0.4.3) + activejob (= 7.0.4.3) + activesupport (= 7.0.4.3) + mail (~> 2.5, >= 2.5.4) + net-imap + net-pop + net-smtp + rails-dom-testing (~> 2.0) + actionpack (7.0.4.3) + actionview (= 7.0.4.3) + activesupport (= 7.0.4.3) + rack (~> 2.0, >= 2.2.0) + rack-test (>= 0.6.3) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.2.0) + actiontext (7.0.4.3) + actionpack (= 7.0.4.3) + activerecord (= 7.0.4.3) + activestorage (= 7.0.4.3) + activesupport (= 7.0.4.3) + globalid (>= 0.6.0) + nokogiri (>= 1.8.5) + actionview (7.0.4.3) + activesupport (= 7.0.4.3) + builder (~> 3.1) + erubi (~> 1.4) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.1, >= 1.2.0) + activejob (7.0.4.3) + activesupport (= 7.0.4.3) + globalid (>= 0.3.6) + activemodel (7.0.4.3) + activesupport (= 7.0.4.3) + activerecord (7.0.4.3) + activemodel (= 7.0.4.3) + activesupport (= 7.0.4.3) + activestorage (7.0.4.3) + actionpack (= 7.0.4.3) + activejob (= 7.0.4.3) + activerecord (= 7.0.4.3) + activesupport (= 7.0.4.3) + marcel (~> 1.0) + mini_mime (>= 1.1.0) + activesupport (7.0.4.3) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 1.6, < 2) + minitest (>= 5.1) + tzinfo (~> 2.0) + bootsnap (1.16.0) + msgpack (~> 1.2) + builder (3.2.4) + concurrent-ruby (1.2.2) + crass (1.0.6) + date (3.3.3) + debug (1.7.2) + irb (>= 1.5.0) + reline (>= 0.3.1) + erubi (1.12.0) + globalid (1.1.0) + activesupport (>= 5.0) + google-protobuf (3.22.2-x86_64-darwin) + google-protobuf (3.22.2-x86_64-linux) + googleapis-common-protos-types (1.5.0) + google-protobuf (~> 3.14) + i18n (1.12.0) + concurrent-ruby (~> 1.0) + io-console (0.6.0) + irb (1.6.4) + reline (>= 0.3.0) + loofah (2.20.0) + crass (~> 1.0.2) + nokogiri (>= 1.5.9) + mail (2.8.1) + mini_mime (>= 0.1.1) + net-imap + net-pop + net-smtp + marcel (1.0.2) + method_source (1.0.0) + mini_mime (1.1.2) + minitest (5.18.0) + msgpack (1.7.0) + net-imap (0.3.4) + date + net-protocol + net-pop (0.1.2) + net-protocol + net-protocol (0.2.1) + timeout + net-smtp (0.3.3) + net-protocol + nio4r (2.7.0) + nokogiri (1.16.2-x86_64-darwin) + racc (~> 1.4) + nokogiri (1.16.2-x86_64-linux) + racc (~> 1.4) + opentelemetry-api (1.1.0) + opentelemetry-common (0.19.6) + opentelemetry-api (~> 1.0) + opentelemetry-exporter-otlp (0.24.0) + google-protobuf (~> 3.19) + googleapis-common-protos-types (~> 1.3) + opentelemetry-api (~> 1.1) + opentelemetry-common (~> 0.19.6) + opentelemetry-sdk (~> 1.2) + opentelemetry-semantic_conventions + opentelemetry-instrumentation-action_pack (0.5.0) + opentelemetry-api (~> 1.0) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-rack (~> 0.21) + opentelemetry-instrumentation-action_view (0.4.0) + opentelemetry-api (~> 1.0) + opentelemetry-instrumentation-active_support (~> 0.1) + opentelemetry-instrumentation-base (~> 0.20) + opentelemetry-instrumentation-active_job (0.4.0) + opentelemetry-api (~> 1.0) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-active_model_serializers (0.19.1) + opentelemetry-api (~> 1.0) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-active_record (0.5.0) + opentelemetry-api (~> 1.0) + opentelemetry-instrumentation-base (~> 0.21.0) + ruby2_keywords + opentelemetry-instrumentation-active_support (0.3.0) + opentelemetry-api (~> 1.0) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-all (0.33.0) + opentelemetry-instrumentation-active_model_serializers (~> 0.19.0) + opentelemetry-instrumentation-aws_sdk (~> 0.3.0) + opentelemetry-instrumentation-bunny (~> 0.19.0) + opentelemetry-instrumentation-concurrent_ruby (~> 0.20.0) + opentelemetry-instrumentation-dalli (~> 0.22.0) + opentelemetry-instrumentation-delayed_job (~> 0.19.0) + opentelemetry-instrumentation-ethon (~> 0.20.0) + opentelemetry-instrumentation-excon (~> 0.20.0) + opentelemetry-instrumentation-faraday (~> 0.22.0) + opentelemetry-instrumentation-graphql (~> 0.24.0) + opentelemetry-instrumentation-http (~> 0.21.0) + opentelemetry-instrumentation-http_client (~> 0.21.0) + opentelemetry-instrumentation-koala (~> 0.19.0) + opentelemetry-instrumentation-lmdb (~> 0.21.0) + opentelemetry-instrumentation-mongo (~> 0.21.0) + opentelemetry-instrumentation-mysql2 (~> 0.22.0) + opentelemetry-instrumentation-net_http (~> 0.21.0) + opentelemetry-instrumentation-pg (~> 0.23.0) + opentelemetry-instrumentation-que (~> 0.5.0) + opentelemetry-instrumentation-racecar (~> 0.1.0) + opentelemetry-instrumentation-rack (~> 0.22.0) + opentelemetry-instrumentation-rails (~> 0.25.0) + opentelemetry-instrumentation-rake (~> 0.1.0) + opentelemetry-instrumentation-rdkafka (~> 0.2.0) + opentelemetry-instrumentation-redis (~> 0.24.0) + opentelemetry-instrumentation-resque (~> 0.3.0) + opentelemetry-instrumentation-restclient (~> 0.21.0) + opentelemetry-instrumentation-ruby_kafka (~> 0.19.0) + opentelemetry-instrumentation-sidekiq (~> 0.22.0) + opentelemetry-instrumentation-sinatra (~> 0.21.0) + opentelemetry-instrumentation-trilogy (~> 0.52.0) + opentelemetry-instrumentation-aws_sdk (0.3.2) + opentelemetry-api (~> 1.0) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-base (0.21.1) + opentelemetry-api (~> 1.0) + opentelemetry-registry (~> 0.1) + opentelemetry-instrumentation-bunny (0.19.1) + opentelemetry-api (~> 1.0) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-concurrent_ruby (0.20.1) + opentelemetry-api (~> 1.0) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-dalli (0.22.2) + opentelemetry-api (~> 1.0) + opentelemetry-common (~> 0.19.3) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-delayed_job (0.19.1) + opentelemetry-api (~> 1.0) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-ethon (0.20.1) + opentelemetry-api (~> 1.0) + opentelemetry-common (~> 0.19.3) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-excon (0.20.1) + opentelemetry-api (~> 1.0) + opentelemetry-common (~> 0.19.3) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-faraday (0.22.0) + opentelemetry-api (~> 1.0) + opentelemetry-common (~> 0.19.3) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-graphql (0.24.0) + opentelemetry-api (~> 1.0) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-http (0.21.0) + opentelemetry-api (~> 1.0) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-http_client (0.21.0) + opentelemetry-api (~> 1.0) + opentelemetry-common (~> 0.19.3) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-koala (0.19.1) + opentelemetry-api (~> 1.0) + opentelemetry-common (~> 0.19.3) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-lmdb (0.21.1) + opentelemetry-api (~> 1.0) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-mongo (0.21.1) + opentelemetry-api (~> 1.0) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-mysql2 (0.22.0) + opentelemetry-api (~> 1.0) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-net_http (0.21.1) + opentelemetry-api (~> 1.0) + opentelemetry-common (~> 0.19.3) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-pg (0.23.0) + opentelemetry-api (~> 1.0) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-que (0.5.1) + opentelemetry-api (~> 1.0) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-racecar (0.1.2) + opentelemetry-api (~> 1.0) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-rack (0.22.1) + opentelemetry-api (~> 1.0) + opentelemetry-common (~> 0.19.3) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-rails (0.25.0) + opentelemetry-api (~> 1.0) + opentelemetry-instrumentation-action_pack (~> 0.5.0) + opentelemetry-instrumentation-action_view (~> 0.4.0) + opentelemetry-instrumentation-active_job (~> 0.4.0) + opentelemetry-instrumentation-active_record (~> 0.5.0) + opentelemetry-instrumentation-active_support (~> 0.3.0) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-rake (0.1.1) + opentelemetry-api (~> 1.0) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-rdkafka (0.2.3) + opentelemetry-api (~> 1.0) + opentelemetry-common (~> 0.19.3) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-redis (0.24.1) + opentelemetry-api (~> 1.0) + opentelemetry-common (~> 0.19.3) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-resque (0.3.1) + opentelemetry-api (~> 1.0) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-restclient (0.21.0) + opentelemetry-api (~> 1.0) + opentelemetry-common (~> 0.19.3) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-ruby_kafka (0.19.1) + opentelemetry-api (~> 1.0) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-sidekiq (0.22.1) + opentelemetry-api (~> 1.0) + opentelemetry-common (~> 0.19.3) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-sinatra (0.21.5) + opentelemetry-api (~> 1.0) + opentelemetry-common (~> 0.19.3) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-rack (~> 0.21) + opentelemetry-instrumentation-trilogy (0.52.0) + opentelemetry-api (~> 1.0) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-semantic_conventions (>= 1.8.0) + opentelemetry-registry (0.2.0) + opentelemetry-api (~> 1.1) + opentelemetry-sdk (1.2.0) + opentelemetry-api (~> 1.1) + opentelemetry-common (~> 0.19.3) + opentelemetry-registry (~> 0.2) + opentelemetry-semantic_conventions + opentelemetry-semantic_conventions (1.8.0) + opentelemetry-api (~> 1.0) + puma (5.6.8) + nio4r (~> 2.0) + racc (1.7.3) + rack (2.2.6.4) + rack-test (2.1.0) + rack (>= 1.3) + rails (7.0.4.3) + actioncable (= 7.0.4.3) + actionmailbox (= 7.0.4.3) + actionmailer (= 7.0.4.3) + actionpack (= 7.0.4.3) + actiontext (= 7.0.4.3) + actionview (= 7.0.4.3) + activejob (= 7.0.4.3) + activemodel (= 7.0.4.3) + activerecord (= 7.0.4.3) + activestorage (= 7.0.4.3) + activesupport (= 7.0.4.3) + bundler (>= 1.15.0) + railties (= 7.0.4.3) + rails-dom-testing (2.0.3) + activesupport (>= 4.2.0) + nokogiri (>= 1.6) + rails-html-sanitizer (1.5.0) + loofah (~> 2.19, >= 2.19.1) + railties (7.0.4.3) + actionpack (= 7.0.4.3) + activesupport (= 7.0.4.3) + method_source + rake (>= 12.2) + thor (~> 1.0) + zeitwerk (~> 2.5) + rake (13.0.6) + reline (0.3.3) + io-console (~> 0.5) + ruby2_keywords (0.0.5) + sqlite3 (1.6.2-x86_64-darwin) + sqlite3 (1.6.2-x86_64-linux) + thor (1.2.1) + timeout (0.3.2) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) + tzinfo-data (1.2023.3) + tzinfo (>= 1.0.0) + websocket-driver (0.7.5) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.5) + zeitwerk (2.6.7) + +PLATFORMS + x86_64-darwin-21 + x86_64-linux + +DEPENDENCIES + bootsnap + debug + opentelemetry-exporter-otlp + opentelemetry-instrumentation-all + opentelemetry-sdk + puma (~> 5.6) + rails (~> 7.0.4, >= 7.0.4.3) + sqlite3 (~> 1.4) + tzinfo-data + +RUBY VERSION + ruby 3.1.2p20 + +BUNDLED WITH + 2.3.12 diff --git a/examples/datadog-propagation/quick_start_api_datadog/Rakefile b/examples/datadog-propagation/quick_start_api_datadog/Rakefile new file mode 100644 index 0000000000..9a5ea7383a --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_datadog/Rakefile @@ -0,0 +1,6 @@ +# Add your own tasks in files placed in lib/tasks ending in .rake, +# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. + +require_relative "config/application" + +Rails.application.load_tasks diff --git a/examples/datadog-propagation/quick_start_api_datadog/app/controllers/application_controller.rb b/examples/datadog-propagation/quick_start_api_datadog/app/controllers/application_controller.rb new file mode 100644 index 0000000000..4ac8823b09 --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_datadog/app/controllers/application_controller.rb @@ -0,0 +1,2 @@ +class ApplicationController < ActionController::API +end diff --git a/examples/datadog-propagation/quick_start_api_datadog/app/controllers/concerns/.keep b/examples/datadog-propagation/quick_start_api_datadog/app/controllers/concerns/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/examples/datadog-propagation/quick_start_api_datadog/app/controllers/hello_controller.rb b/examples/datadog-propagation/quick_start_api_datadog/app/controllers/hello_controller.rb new file mode 100644 index 0000000000..d036645342 --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_datadog/app/controllers/hello_controller.rb @@ -0,0 +1,42 @@ +require 'uri' +require 'net/http' + +class HelloController < ApplicationController + + def local_hello + service_name = ENV['SERVICE_NAME'] + + puts '-----------------------------------------' + puts 'Headers' + puts '-----------------------------------------' + puts request.headers.env.reject { |key| key.to_s.include?('.') }.inspect + puts '-----------------------------------------' + + render json: { hello: 'world!', service: service_name } + end + + def remote_hello + service_name = ENV['SERVICE_NAME'] + remote_hello_api = ENV['REMOTE_API'] + + url = URI("http://#{remote_hello_api}:8080/hello") + + http = Net::HTTP.new(url.host, url.port); + request = Net::HTTP::Get.new(url) + + response = http.request(request) + + # puts '-----------------------------------------' + # puts 'Response' + # puts '-----------------------------------------' + # puts response.body, response.code, response.message, response.each_header.to_h.inspect + # puts '-----------------------------------------' + + if response.code != '200' + return render json: { error: response.body } + end + + parsed_response = JSON.parse(response.body, symbolize_names: true) + render json: { hello: parsed_response[:hello], from: service_name, to: parsed_response[:service]} + end +end diff --git a/examples/datadog-propagation/quick_start_api_datadog/app/models/application_record.rb b/examples/datadog-propagation/quick_start_api_datadog/app/models/application_record.rb new file mode 100644 index 0000000000..b63caeb8a5 --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_datadog/app/models/application_record.rb @@ -0,0 +1,3 @@ +class ApplicationRecord < ActiveRecord::Base + primary_abstract_class +end diff --git a/examples/datadog-propagation/quick_start_api_datadog/app/models/concerns/.keep b/examples/datadog-propagation/quick_start_api_datadog/app/models/concerns/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/examples/datadog-propagation/quick_start_api_datadog/app/views/layouts/mailer.html.erb b/examples/datadog-propagation/quick_start_api_datadog/app/views/layouts/mailer.html.erb new file mode 100644 index 0000000000..cbd34d2e9d --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_datadog/app/views/layouts/mailer.html.erb @@ -0,0 +1,13 @@ + + + + + + + + + <%= yield %> + + diff --git a/examples/datadog-propagation/quick_start_api_datadog/app/views/layouts/mailer.text.erb b/examples/datadog-propagation/quick_start_api_datadog/app/views/layouts/mailer.text.erb new file mode 100644 index 0000000000..37f0bddbd7 --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_datadog/app/views/layouts/mailer.text.erb @@ -0,0 +1 @@ +<%= yield %> diff --git a/examples/datadog-propagation/quick_start_api_datadog/bin/bundle b/examples/datadog-propagation/quick_start_api_datadog/bin/bundle new file mode 100755 index 0000000000..981e650b68 --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_datadog/bin/bundle @@ -0,0 +1,114 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'bundle' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require "rubygems" + +m = Module.new do + module_function + + def invoked_as_script? + File.expand_path($0) == File.expand_path(__FILE__) + end + + def env_var_version + ENV["BUNDLER_VERSION"] + end + + def cli_arg_version + return unless invoked_as_script? # don't want to hijack other binstubs + return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update` + bundler_version = nil + update_index = nil + ARGV.each_with_index do |a, i| + if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN + bundler_version = a + end + next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/ + bundler_version = $1 + update_index = i + end + bundler_version + end + + def gemfile + gemfile = ENV["BUNDLE_GEMFILE"] + return gemfile if gemfile && !gemfile.empty? + + File.expand_path("../Gemfile", __dir__) + end + + def lockfile + lockfile = + case File.basename(gemfile) + when "gems.rb" then gemfile.sub(/\.rb$/, gemfile) + else "#{gemfile}.lock" + end + File.expand_path(lockfile) + end + + def lockfile_version + return unless File.file?(lockfile) + lockfile_contents = File.read(lockfile) + return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/ + Regexp.last_match(1) + end + + def bundler_requirement + @bundler_requirement ||= + env_var_version || cli_arg_version || + bundler_requirement_for(lockfile_version) + end + + def bundler_requirement_for(version) + return "#{Gem::Requirement.default}.a" unless version + + bundler_gem_version = Gem::Version.new(version) + + requirement = bundler_gem_version.approximate_recommendation + + return requirement unless Gem.rubygems_version < Gem::Version.new("2.7.0") + + requirement += ".a" if bundler_gem_version.prerelease? + + requirement + end + + def load_bundler! + ENV["BUNDLE_GEMFILE"] ||= gemfile + + activate_bundler + end + + def activate_bundler + gem_error = activation_error_handling do + gem "bundler", bundler_requirement + end + return if gem_error.nil? + require_error = activation_error_handling do + require "bundler/version" + end + return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION)) + warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`" + exit 42 + end + + def activation_error_handling + yield + nil + rescue StandardError, LoadError => e + e + end +end + +m.load_bundler! + +if m.invoked_as_script? + load Gem.bin_path("bundler", "bundle") +end diff --git a/examples/datadog-propagation/quick_start_api_datadog/bin/rails b/examples/datadog-propagation/quick_start_api_datadog/bin/rails new file mode 100755 index 0000000000..efc0377492 --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_datadog/bin/rails @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +APP_PATH = File.expand_path("../config/application", __dir__) +require_relative "../config/boot" +require "rails/commands" diff --git a/examples/datadog-propagation/quick_start_api_datadog/bin/rake b/examples/datadog-propagation/quick_start_api_datadog/bin/rake new file mode 100755 index 0000000000..4fbf10b960 --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_datadog/bin/rake @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +require_relative "../config/boot" +require "rake" +Rake.application.run diff --git a/examples/datadog-propagation/quick_start_api_datadog/bin/setup b/examples/datadog-propagation/quick_start_api_datadog/bin/setup new file mode 100755 index 0000000000..ec47b79b3b --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_datadog/bin/setup @@ -0,0 +1,33 @@ +#!/usr/bin/env ruby +require "fileutils" + +# path to your application root. +APP_ROOT = File.expand_path("..", __dir__) + +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +FileUtils.chdir APP_ROOT do + # This script is a way to set up or update your development environment automatically. + # This script is idempotent, so that you can run it at any time and get an expectable outcome. + # Add necessary setup steps to this file. + + puts "== Installing dependencies ==" + system! "gem install bundler --conservative" + system("bundle check") || system!("bundle install") + + # puts "\n== Copying sample files ==" + # unless File.exist?("config/database.yml") + # FileUtils.cp "config/database.yml.sample", "config/database.yml" + # end + + puts "\n== Preparing database ==" + system! "bin/rails db:prepare" + + puts "\n== Removing old logs and tempfiles ==" + system! "bin/rails log:clear tmp:clear" + + puts "\n== Restarting application server ==" + system! "bin/rails restart" +end diff --git a/examples/datadog-propagation/quick_start_api_datadog/config.ru b/examples/datadog-propagation/quick_start_api_datadog/config.ru new file mode 100644 index 0000000000..4a3c09a688 --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_datadog/config.ru @@ -0,0 +1,6 @@ +# This file is used by Rack-based servers to start the application. + +require_relative "config/environment" + +run Rails.application +Rails.application.load_server diff --git a/examples/datadog-propagation/quick_start_api_datadog/config/application.rb b/examples/datadog-propagation/quick_start_api_datadog/config/application.rb new file mode 100644 index 0000000000..1159f54282 --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_datadog/config/application.rb @@ -0,0 +1,27 @@ +require_relative "boot" + +require "rails/all" + +# Require the gems listed in Gemfile, including any gems +# you've limited to :test, :development, or :production. +Bundler.require(*Rails.groups) + +module QuickStartApi + class Application < Rails::Application + # Initialize configuration defaults for originally generated Rails version. + config.load_defaults 7.0 + + # Configuration for the application, engines, and railties goes here. + # + # These settings can be overridden in specific environments using the files + # in config/environments, which are processed later. + # + # config.time_zone = "Central Time (US & Canada)" + # config.eager_load_paths << Rails.root.join("extras") + + # Only loads a smaller set of middleware suitable for API only apps. + # Middleware like session, flash, cookies can be added back manually. + # Skip views, helpers and assets when generating a new resource. + config.api_only = true + end +end diff --git a/examples/datadog-propagation/quick_start_api_datadog/config/boot.rb b/examples/datadog-propagation/quick_start_api_datadog/config/boot.rb new file mode 100644 index 0000000000..988a5ddc46 --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_datadog/config/boot.rb @@ -0,0 +1,4 @@ +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) + +require "bundler/setup" # Set up gems listed in the Gemfile. +require "bootsnap/setup" # Speed up boot time by caching expensive operations. diff --git a/examples/datadog-propagation/quick_start_api_datadog/config/cable.yml b/examples/datadog-propagation/quick_start_api_datadog/config/cable.yml new file mode 100644 index 0000000000..1833ec44d1 --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_datadog/config/cable.yml @@ -0,0 +1,10 @@ +development: + adapter: async + +test: + adapter: test + +production: + adapter: redis + url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %> + channel_prefix: quick_start_api_production diff --git a/examples/datadog-propagation/quick_start_api_datadog/config/credentials.yml.enc b/examples/datadog-propagation/quick_start_api_datadog/config/credentials.yml.enc new file mode 100644 index 0000000000..6b44d3d547 --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_datadog/config/credentials.yml.enc @@ -0,0 +1 @@ +MH1ZbWDsGMxBIozSg3pOwH5mlZJ+iv8ZwfHu+nBGSyRGIMKOz9JmMB2PKW0FQ2L+ajPmz98D7uO69w2c1uI5VFHk48I9uEk+s/jQtA3EQ7igpashiAnPr2pGtYEPebcGBeNaB3HKgjGybp81sjR1q/X7/Cnnn9nDBrebOEG6e8HjZzoaprLyTZASWsVcnaOmxaUqAyI7A8H5T97jP8dpghf83t63wO1D9YrBxgDfNkMvbGYzYIeAsM6PePifwIK26YyDpnnzU74o/79KyorcUs7fpNrxOR7alYeI6xreXwcbXyYdDxnFA+N4arrEBCANGKw4rYYpzif/d7BbulGBknHeRjzXoA9jkSpKjWy7yhpV/fD9GizFxqE5cGndOgQMRKbUk7hvfs6TrH4hHpvgyb/X1VD+2ae15SnX--WjCEFC9FcXz/9e8L--A2BU8B6c8wpFQ05SXMEmRQ== \ No newline at end of file diff --git a/examples/datadog-propagation/quick_start_api_datadog/config/database.yml b/examples/datadog-propagation/quick_start_api_datadog/config/database.yml new file mode 100644 index 0000000000..fcba57f19f --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_datadog/config/database.yml @@ -0,0 +1,25 @@ +# SQLite. Versions 3.8.0 and up are supported. +# gem install sqlite3 +# +# Ensure the SQLite 3 gem is defined in your Gemfile +# gem "sqlite3" +# +default: &default + adapter: sqlite3 + pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> + timeout: 5000 + +development: + <<: *default + database: db/development.sqlite3 + +# Warning: The database defined as "test" will be erased and +# re-generated from your development database when you run "rake". +# Do not set this db to the same as development or production. +test: + <<: *default + database: db/test.sqlite3 + +production: + <<: *default + database: db/production.sqlite3 diff --git a/examples/datadog-propagation/quick_start_api_datadog/config/environment.rb b/examples/datadog-propagation/quick_start_api_datadog/config/environment.rb new file mode 100644 index 0000000000..cac5315775 --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_datadog/config/environment.rb @@ -0,0 +1,5 @@ +# Load the Rails application. +require_relative "application" + +# Initialize the Rails application. +Rails.application.initialize! diff --git a/examples/datadog-propagation/quick_start_api_datadog/config/environments/development.rb b/examples/datadog-propagation/quick_start_api_datadog/config/environments/development.rb new file mode 100644 index 0000000000..7a71b46ab5 --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_datadog/config/environments/development.rb @@ -0,0 +1,75 @@ +require "active_support/core_ext/integer/time" + +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # In the development environment your application's code is reloaded any time + # it changes. This slows down response time but is perfect for development + # since you don't have to restart the web server when you make code changes. + config.cache_classes = false + + # Do not eager load code on boot. + config.eager_load = false + + # Show full error reports. + config.consider_all_requests_local = true + + # Enable server timing + config.server_timing = true + + # Enable/disable caching. By default caching is disabled. + # Run rails dev:cache to toggle caching. + if Rails.root.join("tmp/caching-dev.txt").exist? + config.cache_store = :memory_store + config.public_file_server.headers = { + "Cache-Control" => "public, max-age=#{2.days.to_i}" + } + else + config.action_controller.perform_caching = false + + config.cache_store = :null_store + end + + # Store uploaded files on the local file system (see config/storage.yml for options). + config.active_storage.service = :local + + # Don't care if the mailer can't send. + config.action_mailer.raise_delivery_errors = false + + config.action_mailer.perform_caching = false + + # Print deprecation notices to the Rails logger. + config.active_support.deprecation = :log + + # Raise exceptions for disallowed deprecations. + config.active_support.disallowed_deprecation = :raise + + # Tell Active Support which deprecation messages to disallow. + config.active_support.disallowed_deprecation_warnings = [] + + # Raise an error on page load if there are pending migrations. + config.active_record.migration_error = :page_load + + # Highlight code that triggered database queries in logs. + config.active_record.verbose_query_logs = true + + + # Raises error for missing translations. + # config.i18n.raise_on_missing_translations = true + + # Annotate rendered view with file names. + # config.action_view.annotate_rendered_view_with_filenames = true + + # Uncomment if you wish to allow Action Cable access from any origin. + # config.action_cable.disable_request_forgery_protection = true + + # Validate hosts that can access this API + # config.hosts = [ + # IPAddr.new("0.0.0.0/0"), # All IPv4 addresses. + # IPAddr.new("::/0"), # All IPv6 addresses. + # "localhost", # The localhost reserved domain. + # "app", # The internal docker reserved domain. + # ENV["RAILS_DEVELOPMENT_HOSTS"] # Additional comma-separated hosts for development. + # ] + config.hosts.clear +end diff --git a/examples/datadog-propagation/quick_start_api_datadog/config/environments/production.rb b/examples/datadog-propagation/quick_start_api_datadog/config/environments/production.rb new file mode 100644 index 0000000000..87295729d2 --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_datadog/config/environments/production.rb @@ -0,0 +1,95 @@ +require "active_support/core_ext/integer/time" + +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # Code is not reloaded between requests. + config.cache_classes = true + + # Eager load code on boot. This eager loads most of Rails and + # your application in memory, allowing both threaded web servers + # and those relying on copy on write to perform better. + # Rake tasks automatically ignore this option for performance. + config.eager_load = true + + # Full error reports are disabled and caching is turned on. + config.consider_all_requests_local = false + + # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] + # or in config/master.key. This key is used to decrypt credentials (and other encrypted files). + # config.require_master_key = true + + # Disable serving static files from the `/public` folder by default since + # Apache or NGINX already handles this. + config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present? + + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.asset_host = "http://assets.example.com" + + # Specifies the header that your server uses for sending files. + # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for Apache + # config.action_dispatch.x_sendfile_header = "X-Accel-Redirect" # for NGINX + + # Store uploaded files on the local file system (see config/storage.yml for options). + config.active_storage.service = :local + + # Mount Action Cable outside main process or domain. + # config.action_cable.mount_path = nil + # config.action_cable.url = "wss://example.com/cable" + # config.action_cable.allowed_request_origins = [ "http://example.com", /http:\/\/example.*/ ] + + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. + # config.force_ssl = true + + # Include generic and useful information about system operation, but avoid logging too much + # information to avoid inadvertent exposure of personally identifiable information (PII). + config.log_level = :info + + # Prepend all log lines with the following tags. + config.log_tags = [ :request_id ] + + # Use a different cache store in production. + # config.cache_store = :mem_cache_store + + # Use a real queuing backend for Active Job (and separate queues per environment). + # config.active_job.queue_adapter = :resque + # config.active_job.queue_name_prefix = "quick_start_api_production" + + config.action_mailer.perform_caching = false + + # Ignore bad email addresses and do not raise email delivery errors. + # Set this to true and configure the email server for immediate delivery to raise delivery errors. + # config.action_mailer.raise_delivery_errors = false + + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation cannot be found). + config.i18n.fallbacks = true + + # Don't log any deprecations. + config.active_support.report_deprecations = false + + # Use default logging formatter so that PID and timestamp are not suppressed. + config.log_formatter = ::Logger::Formatter.new + + # Use a different logger for distributed setups. + # require "syslog/logger" + # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new "app-name") + + if ENV["RAILS_LOG_TO_STDOUT"].present? + logger = ActiveSupport::Logger.new(STDOUT) + logger.formatter = config.log_formatter + config.logger = ActiveSupport::TaggedLogging.new(logger) + end + + # Do not dump schema after migrations. + config.active_record.dump_schema_after_migration = false + + # Validate hosts that can access this API + config.hosts = [ + IPAddr.new("0.0.0.0/0"), # All IPv4 addresses. + IPAddr.new("::/0"), # All IPv6 addresses. + "localhost", # The localhost reserved domain. + "app", # The internal docker reserved domain. + ENV["RAILS_DEVELOPMENT_HOSTS"] # Additional comma-separated hosts for development. + ] +end diff --git a/examples/datadog-propagation/quick_start_api_datadog/config/environments/test.rb b/examples/datadog-propagation/quick_start_api_datadog/config/environments/test.rb new file mode 100644 index 0000000000..6ea4d1e706 --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_datadog/config/environments/test.rb @@ -0,0 +1,60 @@ +require "active_support/core_ext/integer/time" + +# The test environment is used exclusively to run your application's +# test suite. You never need to work with it otherwise. Remember that +# your test database is "scratch space" for the test suite and is wiped +# and recreated between test runs. Don't rely on the data there! + +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # Turn false under Spring and add config.action_view.cache_template_loading = true. + config.cache_classes = true + + # Eager loading loads your whole application. When running a single test locally, + # this probably isn't necessary. It's a good idea to do in a continuous integration + # system, or in some way before deploying your code. + config.eager_load = ENV["CI"].present? + + # Configure public file server for tests with Cache-Control for performance. + config.public_file_server.enabled = true + config.public_file_server.headers = { + "Cache-Control" => "public, max-age=#{1.hour.to_i}" + } + + # Show full error reports and disable caching. + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + config.cache_store = :null_store + + # Raise exceptions instead of rendering exception templates. + config.action_dispatch.show_exceptions = false + + # Disable request forgery protection in test environment. + config.action_controller.allow_forgery_protection = false + + # Store uploaded files on the local file system in a temporary directory. + config.active_storage.service = :test + + config.action_mailer.perform_caching = false + + # Tell Action Mailer not to deliver emails to the real world. + # The :test delivery method accumulates sent emails in the + # ActionMailer::Base.deliveries array. + config.action_mailer.delivery_method = :test + + # Print deprecation notices to the stderr. + config.active_support.deprecation = :stderr + + # Raise exceptions for disallowed deprecations. + config.active_support.disallowed_deprecation = :raise + + # Tell Active Support which deprecation messages to disallow. + config.active_support.disallowed_deprecation_warnings = [] + + # Raises error for missing translations. + # config.i18n.raise_on_missing_translations = true + + # Annotate rendered view with file names. + # config.action_view.annotate_rendered_view_with_filenames = true +end diff --git a/examples/datadog-propagation/quick_start_api_datadog/config/initializers/cors.rb b/examples/datadog-propagation/quick_start_api_datadog/config/initializers/cors.rb new file mode 100644 index 0000000000..e5a82f162c --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_datadog/config/initializers/cors.rb @@ -0,0 +1,16 @@ +# Be sure to restart your server when you modify this file. + +# Avoid CORS issues when API is called from the frontend app. +# Handle Cross-Origin Resource Sharing (CORS) in order to accept cross-origin AJAX requests. + +# Read more: https://github.com/cyu/rack-cors + +# Rails.application.config.middleware.insert_before 0, Rack::Cors do +# allow do +# origins "example.com" +# +# resource "*", +# headers: :any, +# methods: [:get, :post, :put, :patch, :delete, :options, :head] +# end +# end diff --git a/examples/datadog-propagation/quick_start_api_datadog/config/initializers/datadog.rb b/examples/datadog-propagation/quick_start_api_datadog/config/initializers/datadog.rb new file mode 100644 index 0000000000..47a46373bb --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_datadog/config/initializers/datadog.rb @@ -0,0 +1,39 @@ +require 'net/http' +require 'ddtrace' + +Datadog.configure do |c| + c.service = ENV['SERVICE_NAME'] + c.logger.level = ::Logger::ERROR + + c.tracing.instrument :rails + c.tracing.instrument :http + + # List of header formats that should be extracted + c.tracing.distributed_tracing.propagation_extract_style = [ 'tracecontext' ] + + # List of header formats that should be injected + c.tracing.distributed_tracing.propagation_inject_style = [ 'tracecontext' ] + c.tracing.distributed_tracing.propagation_style = [ 'tracecontext' ] + +end + +module Datadog + module Tracing + module Transport + class SerializableTrace + def to_msgpack(packer = nil) + if ENV.has_key?('INJECT_UPPER_TRACE_ID') + return trace.spans.map { |s| SerializableSpan.new(s) }.to_msgpack(packer) + end + + upper_trace_id = trace.spans.find { |span| span.meta.has_key?('_dd.p.tid') }.meta['_dd.p.tid'] + trace.spans.each do |span| + span.meta["propagation.upper_trace_id"] = upper_trace_id + end + + trace.spans.map { |s| SerializableSpan.new(s) }.to_msgpack(packer) + end + end + end + end +end diff --git a/examples/datadog-propagation/quick_start_api_datadog/config/initializers/filter_parameter_logging.rb b/examples/datadog-propagation/quick_start_api_datadog/config/initializers/filter_parameter_logging.rb new file mode 100644 index 0000000000..adc6568ce8 --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_datadog/config/initializers/filter_parameter_logging.rb @@ -0,0 +1,8 @@ +# Be sure to restart your server when you modify this file. + +# Configure parameters to be filtered from the log file. Use this to limit dissemination of +# sensitive information. See the ActiveSupport::ParameterFilter documentation for supported +# notations and behaviors. +Rails.application.config.filter_parameters += [ + :passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn +] diff --git a/examples/datadog-propagation/quick_start_api_datadog/config/initializers/inflections.rb b/examples/datadog-propagation/quick_start_api_datadog/config/initializers/inflections.rb new file mode 100644 index 0000000000..3860f659ea --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_datadog/config/initializers/inflections.rb @@ -0,0 +1,16 @@ +# Be sure to restart your server when you modify this file. + +# Add new inflection rules using the following format. Inflections +# are locale specific, and you may define rules for as many different +# locales as you wish. All of these examples are active by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.plural /^(ox)$/i, "\\1en" +# inflect.singular /^(ox)en/i, "\\1" +# inflect.irregular "person", "people" +# inflect.uncountable %w( fish sheep ) +# end + +# These inflection rules are supported but not enabled by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.acronym "RESTful" +# end diff --git a/examples/datadog-propagation/quick_start_api_datadog/config/locales/en.yml b/examples/datadog-propagation/quick_start_api_datadog/config/locales/en.yml new file mode 100644 index 0000000000..8ca56fc74f --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_datadog/config/locales/en.yml @@ -0,0 +1,33 @@ +# Files in the config/locales directory are used for internationalization +# and are automatically loaded by Rails. If you want to use locales other +# than English, add the necessary files in this directory. +# +# To use the locales, use `I18n.t`: +# +# I18n.t "hello" +# +# In views, this is aliased to just `t`: +# +# <%= t("hello") %> +# +# To use a different locale, set it with `I18n.locale`: +# +# I18n.locale = :es +# +# This would use the information in config/locales/es.yml. +# +# The following keys must be escaped otherwise they will not be retrieved by +# the default I18n backend: +# +# true, false, on, off, yes, no +# +# Instead, surround them with single quotes. +# +# en: +# "true": "foo" +# +# To learn more, please read the Rails Internationalization guide +# available at https://guides.rubyonrails.org/i18n.html. + +en: + hello: "Hello world" diff --git a/examples/datadog-propagation/quick_start_api_datadog/config/puma.rb b/examples/datadog-propagation/quick_start_api_datadog/config/puma.rb new file mode 100644 index 0000000000..daaf036999 --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_datadog/config/puma.rb @@ -0,0 +1,43 @@ +# Puma can serve each request in a thread from an internal thread pool. +# The `threads` method setting takes two numbers: a minimum and maximum. +# Any libraries that use thread pools should be configured to match +# the maximum value specified for Puma. Default is set to 5 threads for minimum +# and maximum; this matches the default thread size of Active Record. +# +max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } +min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count } +threads min_threads_count, max_threads_count + +# Specifies the `worker_timeout` threshold that Puma will use to wait before +# terminating a worker in development environments. +# +worker_timeout 3600 if ENV.fetch("RAILS_ENV", "development") == "development" + +# Specifies the `port` that Puma will listen on to receive requests; default is 3000. +# +port ENV.fetch("PORT") { 3000 } + +# Specifies the `environment` that Puma will run in. +# +environment ENV.fetch("RAILS_ENV") { "development" } + +# Specifies the `pidfile` that Puma will use. +pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" } + +# Specifies the number of `workers` to boot in clustered mode. +# Workers are forked web server processes. If using threads and workers together +# the concurrency of the application would be max `threads` * `workers`. +# Workers do not work on JRuby or Windows (both of which do not support +# processes). +# +# workers ENV.fetch("WEB_CONCURRENCY") { 2 } + +# Use the `preload_app!` method when specifying a `workers` number. +# This directive tells Puma to first boot the application and load code +# before forking the application. This takes advantage of Copy On Write +# process behavior so workers use less memory. +# +# preload_app! + +# Allow puma to be restarted by `bin/rails restart` command. +plugin :tmp_restart diff --git a/examples/datadog-propagation/quick_start_api_datadog/config/routes.rb b/examples/datadog-propagation/quick_start_api_datadog/config/routes.rb new file mode 100644 index 0000000000..90f773f9ff --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_datadog/config/routes.rb @@ -0,0 +1,5 @@ +Rails.application.routes.draw do + get '/hello', to: 'hello#local_hello' + + get '/remotehello', to: 'hello#remote_hello' +end diff --git a/examples/datadog-propagation/quick_start_api_datadog/config/storage.yml b/examples/datadog-propagation/quick_start_api_datadog/config/storage.yml new file mode 100644 index 0000000000..4942ab6694 --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_datadog/config/storage.yml @@ -0,0 +1,34 @@ +test: + service: Disk + root: <%= Rails.root.join("tmp/storage") %> + +local: + service: Disk + root: <%= Rails.root.join("storage") %> + +# Use bin/rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key) +# amazon: +# service: S3 +# access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %> +# secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %> +# region: us-east-1 +# bucket: your_own_bucket-<%= Rails.env %> + +# Remember not to checkin your GCS keyfile to a repository +# google: +# service: GCS +# project: your_project +# credentials: <%= Rails.root.join("path/to/gcs.keyfile") %> +# bucket: your_own_bucket-<%= Rails.env %> + +# Use bin/rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key) +# microsoft: +# service: AzureStorage +# storage_account_name: your_account_name +# storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %> +# container: your_container_name-<%= Rails.env %> + +# mirror: +# service: Mirror +# primary: local +# mirrors: [ amazon, google, microsoft ] diff --git a/examples/datadog-propagation/quick_start_api_datadog/db/seeds.rb b/examples/datadog-propagation/quick_start_api_datadog/db/seeds.rb new file mode 100644 index 0000000000..bc25fce306 --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_datadog/db/seeds.rb @@ -0,0 +1,7 @@ +# This file should contain all the record creation needed to seed the database with its default values. +# The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup). +# +# Examples: +# +# movies = Movie.create([{ name: "Star Wars" }, { name: "Lord of the Rings" }]) +# Character.create(name: "Luke", movie: movies.first) diff --git a/examples/datadog-propagation/quick_start_api_otel/.gitattributes b/examples/datadog-propagation/quick_start_api_otel/.gitattributes new file mode 100644 index 0000000000..31eeee0b6a --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_otel/.gitattributes @@ -0,0 +1,7 @@ +# See https://git-scm.com/docs/gitattributes for more about git attribute files. + +# Mark the database schema as having been generated. +db/schema.rb linguist-generated + +# Mark any vendored files as having been vendored. +vendor/* linguist-vendored diff --git a/examples/datadog-propagation/quick_start_api_otel/.gitignore b/examples/datadog-propagation/quick_start_api_otel/.gitignore new file mode 100644 index 0000000000..12439e5858 --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_otel/.gitignore @@ -0,0 +1,33 @@ +# See https://help.github.com/articles/ignoring-files for more about ignoring files. +# +# If you find yourself ignoring temporary files generated by your text editor +# or operating system, you probably want to add a global ignore instead: +# git config --global core.excludesfile '~/.gitignore_global' + +# Ignore bundler config. +/.bundle + +# Ignore the default SQLite database. +/db/*.sqlite3 +/db/*.sqlite3-* + +# Ignore all logfiles and tempfiles. +/log/* +/tmp/* +!/log/.keep +!/tmp/.keep + +# Ignore pidfiles, but keep the directory. +/tmp/pids/* +!/tmp/pids/ +!/tmp/pids/.keep + +# Ignore uploaded files in development. +/storage/* +!/storage/.keep +/tmp/storage/* +!/tmp/storage/ +!/tmp/storage/.keep + +# Ignore master key for decrypting credentials and more. +/config/master.key diff --git a/examples/datadog-propagation/quick_start_api_otel/.ruby-version b/examples/datadog-propagation/quick_start_api_otel/.ruby-version new file mode 100644 index 0000000000..7bde84d06c --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_otel/.ruby-version @@ -0,0 +1 @@ +ruby-3.1.2 diff --git a/examples/datadog-propagation/quick_start_api_otel/Dockerfile b/examples/datadog-propagation/quick_start_api_otel/Dockerfile new file mode 100644 index 0000000000..9658e51a8c --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_otel/Dockerfile @@ -0,0 +1,11 @@ +FROM ruby:3.1.2-alpine +WORKDIR /usr/src/app + +COPY Gemfile Gemfile.lock . +RUN apk update && apk add make gcc musl-dev && bundle install + +COPY . . +RUN chmod 666 ./Gemfile.lock +EXPOSE 8080 + +CMD [ "bundle", "exec", "rails", "server", "--port", "8080", "--binding", "0.0.0.0" ] diff --git a/examples/datadog-propagation/quick_start_api_otel/Gemfile b/examples/datadog-propagation/quick_start_api_otel/Gemfile new file mode 100644 index 0000000000..4508202bb8 --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_otel/Gemfile @@ -0,0 +1,53 @@ +source "https://rubygems.org" +git_source(:github) { |repo| "https://github.com/#{repo}.git" } + +ruby "3.1.2" + +# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main" +gem "rails", "~> 7.0.4", ">= 7.0.4.3" + +# Use sqlite3 as the database for Active Record +gem "sqlite3", "~> 1.4" + +# Use the Puma web server [https://github.com/puma/puma] +gem "puma", "~> 5.6" + +# Build JSON APIs with ease [https://github.com/rails/jbuilder] +# gem "jbuilder" + +# Use Redis adapter to run Action Cable in production +# gem "redis", "~> 4.0" + +# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis] +# gem "kredis" + +# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword] +# gem "bcrypt", "~> 3.1.7" + +# Windows does not include zoneinfo files, so bundle the tzinfo-data gem +gem "tzinfo-data" + +# Adding support for Open Telemetry +gem 'opentelemetry-sdk' +gem 'opentelemetry-exporter-otlp' +gem 'opentelemetry-instrumentation-all' + +# Reduces boot times through caching; required in config/boot.rb +gem "bootsnap", require: false + +# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images] +# gem "image_processing", "~> 1.2" + +# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible +# gem "rack-cors" + +group :development, :test do + # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem + gem "debug", platforms: %i[ mri mingw x64_mingw ] +end + +group :development do + # Speed up commands on slow machines / big apps [https://github.com/rails/spring] + # gem "spring" +end + diff --git a/examples/datadog-propagation/quick_start_api_otel/Gemfile.lock b/examples/datadog-propagation/quick_start_api_otel/Gemfile.lock new file mode 100644 index 0000000000..dd40ca97d4 --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_otel/Gemfile.lock @@ -0,0 +1,370 @@ +GEM + remote: https://rubygems.org/ + specs: + actioncable (7.0.4.3) + actionpack (= 7.0.4.3) + activesupport (= 7.0.4.3) + nio4r (~> 2.0) + websocket-driver (>= 0.6.1) + actionmailbox (7.0.4.3) + actionpack (= 7.0.4.3) + activejob (= 7.0.4.3) + activerecord (= 7.0.4.3) + activestorage (= 7.0.4.3) + activesupport (= 7.0.4.3) + mail (>= 2.7.1) + net-imap + net-pop + net-smtp + actionmailer (7.0.4.3) + actionpack (= 7.0.4.3) + actionview (= 7.0.4.3) + activejob (= 7.0.4.3) + activesupport (= 7.0.4.3) + mail (~> 2.5, >= 2.5.4) + net-imap + net-pop + net-smtp + rails-dom-testing (~> 2.0) + actionpack (7.0.4.3) + actionview (= 7.0.4.3) + activesupport (= 7.0.4.3) + rack (~> 2.0, >= 2.2.0) + rack-test (>= 0.6.3) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.2.0) + actiontext (7.0.4.3) + actionpack (= 7.0.4.3) + activerecord (= 7.0.4.3) + activestorage (= 7.0.4.3) + activesupport (= 7.0.4.3) + globalid (>= 0.6.0) + nokogiri (>= 1.8.5) + actionview (7.0.4.3) + activesupport (= 7.0.4.3) + builder (~> 3.1) + erubi (~> 1.4) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.1, >= 1.2.0) + activejob (7.0.4.3) + activesupport (= 7.0.4.3) + globalid (>= 0.3.6) + activemodel (7.0.4.3) + activesupport (= 7.0.4.3) + activerecord (7.0.4.3) + activemodel (= 7.0.4.3) + activesupport (= 7.0.4.3) + activestorage (7.0.4.3) + actionpack (= 7.0.4.3) + activejob (= 7.0.4.3) + activerecord (= 7.0.4.3) + activesupport (= 7.0.4.3) + marcel (~> 1.0) + mini_mime (>= 1.1.0) + activesupport (7.0.4.3) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 1.6, < 2) + minitest (>= 5.1) + tzinfo (~> 2.0) + bootsnap (1.16.0) + msgpack (~> 1.2) + builder (3.2.4) + concurrent-ruby (1.2.2) + crass (1.0.6) + date (3.3.3) + debug (1.7.2) + irb (>= 1.5.0) + reline (>= 0.3.1) + erubi (1.12.0) + globalid (1.1.0) + activesupport (>= 5.0) + google-protobuf (3.22.2-x86_64-darwin) + google-protobuf (3.22.2-x86_64-linux) + googleapis-common-protos-types (1.5.0) + google-protobuf (~> 3.14) + i18n (1.12.0) + concurrent-ruby (~> 1.0) + io-console (0.6.0) + irb (1.6.4) + reline (>= 0.3.0) + loofah (2.20.0) + crass (~> 1.0.2) + nokogiri (>= 1.5.9) + mail (2.8.1) + mini_mime (>= 0.1.1) + net-imap + net-pop + net-smtp + marcel (1.0.2) + method_source (1.0.0) + mini_mime (1.1.2) + minitest (5.18.0) + msgpack (1.7.0) + net-imap (0.3.4) + date + net-protocol + net-pop (0.1.2) + net-protocol + net-protocol (0.2.1) + timeout + net-smtp (0.3.3) + net-protocol + nio4r (2.7.0) + nokogiri (1.16.2-x86_64-darwin) + racc (~> 1.4) + nokogiri (1.16.2-x86_64-linux) + racc (~> 1.4) + opentelemetry-api (1.1.0) + opentelemetry-common (0.19.6) + opentelemetry-api (~> 1.0) + opentelemetry-exporter-otlp (0.24.0) + google-protobuf (~> 3.19) + googleapis-common-protos-types (~> 1.3) + opentelemetry-api (~> 1.1) + opentelemetry-common (~> 0.19.6) + opentelemetry-sdk (~> 1.2) + opentelemetry-semantic_conventions + opentelemetry-instrumentation-action_pack (0.5.0) + opentelemetry-api (~> 1.0) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-rack (~> 0.21) + opentelemetry-instrumentation-action_view (0.4.0) + opentelemetry-api (~> 1.0) + opentelemetry-instrumentation-active_support (~> 0.1) + opentelemetry-instrumentation-base (~> 0.20) + opentelemetry-instrumentation-active_job (0.4.0) + opentelemetry-api (~> 1.0) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-active_model_serializers (0.19.1) + opentelemetry-api (~> 1.0) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-active_record (0.5.0) + opentelemetry-api (~> 1.0) + opentelemetry-instrumentation-base (~> 0.21.0) + ruby2_keywords + opentelemetry-instrumentation-active_support (0.3.0) + opentelemetry-api (~> 1.0) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-all (0.33.0) + opentelemetry-instrumentation-active_model_serializers (~> 0.19.0) + opentelemetry-instrumentation-aws_sdk (~> 0.3.0) + opentelemetry-instrumentation-bunny (~> 0.19.0) + opentelemetry-instrumentation-concurrent_ruby (~> 0.20.0) + opentelemetry-instrumentation-dalli (~> 0.22.0) + opentelemetry-instrumentation-delayed_job (~> 0.19.0) + opentelemetry-instrumentation-ethon (~> 0.20.0) + opentelemetry-instrumentation-excon (~> 0.20.0) + opentelemetry-instrumentation-faraday (~> 0.22.0) + opentelemetry-instrumentation-graphql (~> 0.24.0) + opentelemetry-instrumentation-http (~> 0.21.0) + opentelemetry-instrumentation-http_client (~> 0.21.0) + opentelemetry-instrumentation-koala (~> 0.19.0) + opentelemetry-instrumentation-lmdb (~> 0.21.0) + opentelemetry-instrumentation-mongo (~> 0.21.0) + opentelemetry-instrumentation-mysql2 (~> 0.22.0) + opentelemetry-instrumentation-net_http (~> 0.21.0) + opentelemetry-instrumentation-pg (~> 0.23.0) + opentelemetry-instrumentation-que (~> 0.5.0) + opentelemetry-instrumentation-racecar (~> 0.1.0) + opentelemetry-instrumentation-rack (~> 0.22.0) + opentelemetry-instrumentation-rails (~> 0.25.0) + opentelemetry-instrumentation-rake (~> 0.1.0) + opentelemetry-instrumentation-rdkafka (~> 0.2.0) + opentelemetry-instrumentation-redis (~> 0.24.0) + opentelemetry-instrumentation-resque (~> 0.3.0) + opentelemetry-instrumentation-restclient (~> 0.21.0) + opentelemetry-instrumentation-ruby_kafka (~> 0.19.0) + opentelemetry-instrumentation-sidekiq (~> 0.22.0) + opentelemetry-instrumentation-sinatra (~> 0.21.0) + opentelemetry-instrumentation-trilogy (~> 0.52.0) + opentelemetry-instrumentation-aws_sdk (0.3.2) + opentelemetry-api (~> 1.0) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-base (0.21.1) + opentelemetry-api (~> 1.0) + opentelemetry-registry (~> 0.1) + opentelemetry-instrumentation-bunny (0.19.1) + opentelemetry-api (~> 1.0) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-concurrent_ruby (0.20.1) + opentelemetry-api (~> 1.0) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-dalli (0.22.2) + opentelemetry-api (~> 1.0) + opentelemetry-common (~> 0.19.3) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-delayed_job (0.19.1) + opentelemetry-api (~> 1.0) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-ethon (0.20.1) + opentelemetry-api (~> 1.0) + opentelemetry-common (~> 0.19.3) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-excon (0.20.1) + opentelemetry-api (~> 1.0) + opentelemetry-common (~> 0.19.3) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-faraday (0.22.0) + opentelemetry-api (~> 1.0) + opentelemetry-common (~> 0.19.3) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-graphql (0.24.0) + opentelemetry-api (~> 1.0) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-http (0.21.0) + opentelemetry-api (~> 1.0) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-http_client (0.21.0) + opentelemetry-api (~> 1.0) + opentelemetry-common (~> 0.19.3) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-koala (0.19.1) + opentelemetry-api (~> 1.0) + opentelemetry-common (~> 0.19.3) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-lmdb (0.21.1) + opentelemetry-api (~> 1.0) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-mongo (0.21.1) + opentelemetry-api (~> 1.0) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-mysql2 (0.22.0) + opentelemetry-api (~> 1.0) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-net_http (0.21.1) + opentelemetry-api (~> 1.0) + opentelemetry-common (~> 0.19.3) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-pg (0.23.0) + opentelemetry-api (~> 1.0) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-que (0.5.1) + opentelemetry-api (~> 1.0) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-racecar (0.1.2) + opentelemetry-api (~> 1.0) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-rack (0.22.1) + opentelemetry-api (~> 1.0) + opentelemetry-common (~> 0.19.3) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-rails (0.25.0) + opentelemetry-api (~> 1.0) + opentelemetry-instrumentation-action_pack (~> 0.5.0) + opentelemetry-instrumentation-action_view (~> 0.4.0) + opentelemetry-instrumentation-active_job (~> 0.4.0) + opentelemetry-instrumentation-active_record (~> 0.5.0) + opentelemetry-instrumentation-active_support (~> 0.3.0) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-rake (0.1.1) + opentelemetry-api (~> 1.0) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-rdkafka (0.2.3) + opentelemetry-api (~> 1.0) + opentelemetry-common (~> 0.19.3) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-redis (0.24.1) + opentelemetry-api (~> 1.0) + opentelemetry-common (~> 0.19.3) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-resque (0.3.1) + opentelemetry-api (~> 1.0) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-restclient (0.21.0) + opentelemetry-api (~> 1.0) + opentelemetry-common (~> 0.19.3) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-ruby_kafka (0.19.1) + opentelemetry-api (~> 1.0) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-sidekiq (0.22.1) + opentelemetry-api (~> 1.0) + opentelemetry-common (~> 0.19.3) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-sinatra (0.21.5) + opentelemetry-api (~> 1.0) + opentelemetry-common (~> 0.19.3) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-instrumentation-rack (~> 0.21) + opentelemetry-instrumentation-trilogy (0.52.0) + opentelemetry-api (~> 1.0) + opentelemetry-instrumentation-base (~> 0.21.0) + opentelemetry-semantic_conventions (>= 1.8.0) + opentelemetry-registry (0.2.0) + opentelemetry-api (~> 1.1) + opentelemetry-sdk (1.2.0) + opentelemetry-api (~> 1.1) + opentelemetry-common (~> 0.19.3) + opentelemetry-registry (~> 0.2) + opentelemetry-semantic_conventions + opentelemetry-semantic_conventions (1.8.0) + opentelemetry-api (~> 1.0) + puma (5.6.8) + nio4r (~> 2.0) + racc (1.7.3) + rack (2.2.6.4) + rack-test (2.1.0) + rack (>= 1.3) + rails (7.0.4.3) + actioncable (= 7.0.4.3) + actionmailbox (= 7.0.4.3) + actionmailer (= 7.0.4.3) + actionpack (= 7.0.4.3) + actiontext (= 7.0.4.3) + actionview (= 7.0.4.3) + activejob (= 7.0.4.3) + activemodel (= 7.0.4.3) + activerecord (= 7.0.4.3) + activestorage (= 7.0.4.3) + activesupport (= 7.0.4.3) + bundler (>= 1.15.0) + railties (= 7.0.4.3) + rails-dom-testing (2.0.3) + activesupport (>= 4.2.0) + nokogiri (>= 1.6) + rails-html-sanitizer (1.5.0) + loofah (~> 2.19, >= 2.19.1) + railties (7.0.4.3) + actionpack (= 7.0.4.3) + activesupport (= 7.0.4.3) + method_source + rake (>= 12.2) + thor (~> 1.0) + zeitwerk (~> 2.5) + rake (13.0.6) + reline (0.3.3) + io-console (~> 0.5) + ruby2_keywords (0.0.5) + sqlite3 (1.6.2-x86_64-darwin) + sqlite3 (1.6.2-x86_64-linux) + thor (1.2.1) + timeout (0.3.2) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) + tzinfo-data (1.2023.3) + tzinfo (>= 1.0.0) + websocket-driver (0.7.5) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.5) + zeitwerk (2.6.7) + +PLATFORMS + x86_64-darwin-21 + x86_64-linux + +DEPENDENCIES + bootsnap + debug + opentelemetry-exporter-otlp + opentelemetry-instrumentation-all + opentelemetry-sdk + puma (~> 5.6) + rails (~> 7.0.4, >= 7.0.4.3) + sqlite3 (~> 1.4) + tzinfo-data + +RUBY VERSION + ruby 3.1.2p20 + +BUNDLED WITH + 2.3.12 diff --git a/examples/datadog-propagation/quick_start_api_otel/Rakefile b/examples/datadog-propagation/quick_start_api_otel/Rakefile new file mode 100644 index 0000000000..9a5ea7383a --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_otel/Rakefile @@ -0,0 +1,6 @@ +# Add your own tasks in files placed in lib/tasks ending in .rake, +# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. + +require_relative "config/application" + +Rails.application.load_tasks diff --git a/examples/datadog-propagation/quick_start_api_otel/app/controllers/application_controller.rb b/examples/datadog-propagation/quick_start_api_otel/app/controllers/application_controller.rb new file mode 100644 index 0000000000..4ac8823b09 --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_otel/app/controllers/application_controller.rb @@ -0,0 +1,2 @@ +class ApplicationController < ActionController::API +end diff --git a/examples/datadog-propagation/quick_start_api_otel/app/controllers/concerns/.keep b/examples/datadog-propagation/quick_start_api_otel/app/controllers/concerns/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/examples/datadog-propagation/quick_start_api_otel/app/controllers/hello_controller.rb b/examples/datadog-propagation/quick_start_api_otel/app/controllers/hello_controller.rb new file mode 100644 index 0000000000..d036645342 --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_otel/app/controllers/hello_controller.rb @@ -0,0 +1,42 @@ +require 'uri' +require 'net/http' + +class HelloController < ApplicationController + + def local_hello + service_name = ENV['SERVICE_NAME'] + + puts '-----------------------------------------' + puts 'Headers' + puts '-----------------------------------------' + puts request.headers.env.reject { |key| key.to_s.include?('.') }.inspect + puts '-----------------------------------------' + + render json: { hello: 'world!', service: service_name } + end + + def remote_hello + service_name = ENV['SERVICE_NAME'] + remote_hello_api = ENV['REMOTE_API'] + + url = URI("http://#{remote_hello_api}:8080/hello") + + http = Net::HTTP.new(url.host, url.port); + request = Net::HTTP::Get.new(url) + + response = http.request(request) + + # puts '-----------------------------------------' + # puts 'Response' + # puts '-----------------------------------------' + # puts response.body, response.code, response.message, response.each_header.to_h.inspect + # puts '-----------------------------------------' + + if response.code != '200' + return render json: { error: response.body } + end + + parsed_response = JSON.parse(response.body, symbolize_names: true) + render json: { hello: parsed_response[:hello], from: service_name, to: parsed_response[:service]} + end +end diff --git a/examples/datadog-propagation/quick_start_api_otel/app/models/application_record.rb b/examples/datadog-propagation/quick_start_api_otel/app/models/application_record.rb new file mode 100644 index 0000000000..b63caeb8a5 --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_otel/app/models/application_record.rb @@ -0,0 +1,3 @@ +class ApplicationRecord < ActiveRecord::Base + primary_abstract_class +end diff --git a/examples/datadog-propagation/quick_start_api_otel/app/models/concerns/.keep b/examples/datadog-propagation/quick_start_api_otel/app/models/concerns/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/examples/datadog-propagation/quick_start_api_otel/app/views/layouts/mailer.html.erb b/examples/datadog-propagation/quick_start_api_otel/app/views/layouts/mailer.html.erb new file mode 100644 index 0000000000..cbd34d2e9d --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_otel/app/views/layouts/mailer.html.erb @@ -0,0 +1,13 @@ + + + + + + + + + <%= yield %> + + diff --git a/examples/datadog-propagation/quick_start_api_otel/app/views/layouts/mailer.text.erb b/examples/datadog-propagation/quick_start_api_otel/app/views/layouts/mailer.text.erb new file mode 100644 index 0000000000..37f0bddbd7 --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_otel/app/views/layouts/mailer.text.erb @@ -0,0 +1 @@ +<%= yield %> diff --git a/examples/datadog-propagation/quick_start_api_otel/bin/bundle b/examples/datadog-propagation/quick_start_api_otel/bin/bundle new file mode 100755 index 0000000000..981e650b68 --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_otel/bin/bundle @@ -0,0 +1,114 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'bundle' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require "rubygems" + +m = Module.new do + module_function + + def invoked_as_script? + File.expand_path($0) == File.expand_path(__FILE__) + end + + def env_var_version + ENV["BUNDLER_VERSION"] + end + + def cli_arg_version + return unless invoked_as_script? # don't want to hijack other binstubs + return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update` + bundler_version = nil + update_index = nil + ARGV.each_with_index do |a, i| + if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN + bundler_version = a + end + next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/ + bundler_version = $1 + update_index = i + end + bundler_version + end + + def gemfile + gemfile = ENV["BUNDLE_GEMFILE"] + return gemfile if gemfile && !gemfile.empty? + + File.expand_path("../Gemfile", __dir__) + end + + def lockfile + lockfile = + case File.basename(gemfile) + when "gems.rb" then gemfile.sub(/\.rb$/, gemfile) + else "#{gemfile}.lock" + end + File.expand_path(lockfile) + end + + def lockfile_version + return unless File.file?(lockfile) + lockfile_contents = File.read(lockfile) + return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/ + Regexp.last_match(1) + end + + def bundler_requirement + @bundler_requirement ||= + env_var_version || cli_arg_version || + bundler_requirement_for(lockfile_version) + end + + def bundler_requirement_for(version) + return "#{Gem::Requirement.default}.a" unless version + + bundler_gem_version = Gem::Version.new(version) + + requirement = bundler_gem_version.approximate_recommendation + + return requirement unless Gem.rubygems_version < Gem::Version.new("2.7.0") + + requirement += ".a" if bundler_gem_version.prerelease? + + requirement + end + + def load_bundler! + ENV["BUNDLE_GEMFILE"] ||= gemfile + + activate_bundler + end + + def activate_bundler + gem_error = activation_error_handling do + gem "bundler", bundler_requirement + end + return if gem_error.nil? + require_error = activation_error_handling do + require "bundler/version" + end + return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION)) + warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`" + exit 42 + end + + def activation_error_handling + yield + nil + rescue StandardError, LoadError => e + e + end +end + +m.load_bundler! + +if m.invoked_as_script? + load Gem.bin_path("bundler", "bundle") +end diff --git a/examples/datadog-propagation/quick_start_api_otel/bin/rails b/examples/datadog-propagation/quick_start_api_otel/bin/rails new file mode 100755 index 0000000000..efc0377492 --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_otel/bin/rails @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +APP_PATH = File.expand_path("../config/application", __dir__) +require_relative "../config/boot" +require "rails/commands" diff --git a/examples/datadog-propagation/quick_start_api_otel/bin/rake b/examples/datadog-propagation/quick_start_api_otel/bin/rake new file mode 100755 index 0000000000..4fbf10b960 --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_otel/bin/rake @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +require_relative "../config/boot" +require "rake" +Rake.application.run diff --git a/examples/datadog-propagation/quick_start_api_otel/bin/setup b/examples/datadog-propagation/quick_start_api_otel/bin/setup new file mode 100755 index 0000000000..ec47b79b3b --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_otel/bin/setup @@ -0,0 +1,33 @@ +#!/usr/bin/env ruby +require "fileutils" + +# path to your application root. +APP_ROOT = File.expand_path("..", __dir__) + +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +FileUtils.chdir APP_ROOT do + # This script is a way to set up or update your development environment automatically. + # This script is idempotent, so that you can run it at any time and get an expectable outcome. + # Add necessary setup steps to this file. + + puts "== Installing dependencies ==" + system! "gem install bundler --conservative" + system("bundle check") || system!("bundle install") + + # puts "\n== Copying sample files ==" + # unless File.exist?("config/database.yml") + # FileUtils.cp "config/database.yml.sample", "config/database.yml" + # end + + puts "\n== Preparing database ==" + system! "bin/rails db:prepare" + + puts "\n== Removing old logs and tempfiles ==" + system! "bin/rails log:clear tmp:clear" + + puts "\n== Restarting application server ==" + system! "bin/rails restart" +end diff --git a/examples/datadog-propagation/quick_start_api_otel/config.ru b/examples/datadog-propagation/quick_start_api_otel/config.ru new file mode 100644 index 0000000000..4a3c09a688 --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_otel/config.ru @@ -0,0 +1,6 @@ +# This file is used by Rack-based servers to start the application. + +require_relative "config/environment" + +run Rails.application +Rails.application.load_server diff --git a/examples/datadog-propagation/quick_start_api_otel/config/application.rb b/examples/datadog-propagation/quick_start_api_otel/config/application.rb new file mode 100644 index 0000000000..1159f54282 --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_otel/config/application.rb @@ -0,0 +1,27 @@ +require_relative "boot" + +require "rails/all" + +# Require the gems listed in Gemfile, including any gems +# you've limited to :test, :development, or :production. +Bundler.require(*Rails.groups) + +module QuickStartApi + class Application < Rails::Application + # Initialize configuration defaults for originally generated Rails version. + config.load_defaults 7.0 + + # Configuration for the application, engines, and railties goes here. + # + # These settings can be overridden in specific environments using the files + # in config/environments, which are processed later. + # + # config.time_zone = "Central Time (US & Canada)" + # config.eager_load_paths << Rails.root.join("extras") + + # Only loads a smaller set of middleware suitable for API only apps. + # Middleware like session, flash, cookies can be added back manually. + # Skip views, helpers and assets when generating a new resource. + config.api_only = true + end +end diff --git a/examples/datadog-propagation/quick_start_api_otel/config/boot.rb b/examples/datadog-propagation/quick_start_api_otel/config/boot.rb new file mode 100644 index 0000000000..988a5ddc46 --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_otel/config/boot.rb @@ -0,0 +1,4 @@ +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) + +require "bundler/setup" # Set up gems listed in the Gemfile. +require "bootsnap/setup" # Speed up boot time by caching expensive operations. diff --git a/examples/datadog-propagation/quick_start_api_otel/config/cable.yml b/examples/datadog-propagation/quick_start_api_otel/config/cable.yml new file mode 100644 index 0000000000..1833ec44d1 --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_otel/config/cable.yml @@ -0,0 +1,10 @@ +development: + adapter: async + +test: + adapter: test + +production: + adapter: redis + url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %> + channel_prefix: quick_start_api_production diff --git a/examples/datadog-propagation/quick_start_api_otel/config/credentials.yml.enc b/examples/datadog-propagation/quick_start_api_otel/config/credentials.yml.enc new file mode 100644 index 0000000000..6b44d3d547 --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_otel/config/credentials.yml.enc @@ -0,0 +1 @@ +MH1ZbWDsGMxBIozSg3pOwH5mlZJ+iv8ZwfHu+nBGSyRGIMKOz9JmMB2PKW0FQ2L+ajPmz98D7uO69w2c1uI5VFHk48I9uEk+s/jQtA3EQ7igpashiAnPr2pGtYEPebcGBeNaB3HKgjGybp81sjR1q/X7/Cnnn9nDBrebOEG6e8HjZzoaprLyTZASWsVcnaOmxaUqAyI7A8H5T97jP8dpghf83t63wO1D9YrBxgDfNkMvbGYzYIeAsM6PePifwIK26YyDpnnzU74o/79KyorcUs7fpNrxOR7alYeI6xreXwcbXyYdDxnFA+N4arrEBCANGKw4rYYpzif/d7BbulGBknHeRjzXoA9jkSpKjWy7yhpV/fD9GizFxqE5cGndOgQMRKbUk7hvfs6TrH4hHpvgyb/X1VD+2ae15SnX--WjCEFC9FcXz/9e8L--A2BU8B6c8wpFQ05SXMEmRQ== \ No newline at end of file diff --git a/examples/datadog-propagation/quick_start_api_otel/config/database.yml b/examples/datadog-propagation/quick_start_api_otel/config/database.yml new file mode 100644 index 0000000000..fcba57f19f --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_otel/config/database.yml @@ -0,0 +1,25 @@ +# SQLite. Versions 3.8.0 and up are supported. +# gem install sqlite3 +# +# Ensure the SQLite 3 gem is defined in your Gemfile +# gem "sqlite3" +# +default: &default + adapter: sqlite3 + pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> + timeout: 5000 + +development: + <<: *default + database: db/development.sqlite3 + +# Warning: The database defined as "test" will be erased and +# re-generated from your development database when you run "rake". +# Do not set this db to the same as development or production. +test: + <<: *default + database: db/test.sqlite3 + +production: + <<: *default + database: db/production.sqlite3 diff --git a/examples/datadog-propagation/quick_start_api_otel/config/environment.rb b/examples/datadog-propagation/quick_start_api_otel/config/environment.rb new file mode 100644 index 0000000000..cac5315775 --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_otel/config/environment.rb @@ -0,0 +1,5 @@ +# Load the Rails application. +require_relative "application" + +# Initialize the Rails application. +Rails.application.initialize! diff --git a/examples/datadog-propagation/quick_start_api_otel/config/environments/development.rb b/examples/datadog-propagation/quick_start_api_otel/config/environments/development.rb new file mode 100644 index 0000000000..7a71b46ab5 --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_otel/config/environments/development.rb @@ -0,0 +1,75 @@ +require "active_support/core_ext/integer/time" + +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # In the development environment your application's code is reloaded any time + # it changes. This slows down response time but is perfect for development + # since you don't have to restart the web server when you make code changes. + config.cache_classes = false + + # Do not eager load code on boot. + config.eager_load = false + + # Show full error reports. + config.consider_all_requests_local = true + + # Enable server timing + config.server_timing = true + + # Enable/disable caching. By default caching is disabled. + # Run rails dev:cache to toggle caching. + if Rails.root.join("tmp/caching-dev.txt").exist? + config.cache_store = :memory_store + config.public_file_server.headers = { + "Cache-Control" => "public, max-age=#{2.days.to_i}" + } + else + config.action_controller.perform_caching = false + + config.cache_store = :null_store + end + + # Store uploaded files on the local file system (see config/storage.yml for options). + config.active_storage.service = :local + + # Don't care if the mailer can't send. + config.action_mailer.raise_delivery_errors = false + + config.action_mailer.perform_caching = false + + # Print deprecation notices to the Rails logger. + config.active_support.deprecation = :log + + # Raise exceptions for disallowed deprecations. + config.active_support.disallowed_deprecation = :raise + + # Tell Active Support which deprecation messages to disallow. + config.active_support.disallowed_deprecation_warnings = [] + + # Raise an error on page load if there are pending migrations. + config.active_record.migration_error = :page_load + + # Highlight code that triggered database queries in logs. + config.active_record.verbose_query_logs = true + + + # Raises error for missing translations. + # config.i18n.raise_on_missing_translations = true + + # Annotate rendered view with file names. + # config.action_view.annotate_rendered_view_with_filenames = true + + # Uncomment if you wish to allow Action Cable access from any origin. + # config.action_cable.disable_request_forgery_protection = true + + # Validate hosts that can access this API + # config.hosts = [ + # IPAddr.new("0.0.0.0/0"), # All IPv4 addresses. + # IPAddr.new("::/0"), # All IPv6 addresses. + # "localhost", # The localhost reserved domain. + # "app", # The internal docker reserved domain. + # ENV["RAILS_DEVELOPMENT_HOSTS"] # Additional comma-separated hosts for development. + # ] + config.hosts.clear +end diff --git a/examples/datadog-propagation/quick_start_api_otel/config/environments/production.rb b/examples/datadog-propagation/quick_start_api_otel/config/environments/production.rb new file mode 100644 index 0000000000..87295729d2 --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_otel/config/environments/production.rb @@ -0,0 +1,95 @@ +require "active_support/core_ext/integer/time" + +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # Code is not reloaded between requests. + config.cache_classes = true + + # Eager load code on boot. This eager loads most of Rails and + # your application in memory, allowing both threaded web servers + # and those relying on copy on write to perform better. + # Rake tasks automatically ignore this option for performance. + config.eager_load = true + + # Full error reports are disabled and caching is turned on. + config.consider_all_requests_local = false + + # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] + # or in config/master.key. This key is used to decrypt credentials (and other encrypted files). + # config.require_master_key = true + + # Disable serving static files from the `/public` folder by default since + # Apache or NGINX already handles this. + config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present? + + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.asset_host = "http://assets.example.com" + + # Specifies the header that your server uses for sending files. + # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for Apache + # config.action_dispatch.x_sendfile_header = "X-Accel-Redirect" # for NGINX + + # Store uploaded files on the local file system (see config/storage.yml for options). + config.active_storage.service = :local + + # Mount Action Cable outside main process or domain. + # config.action_cable.mount_path = nil + # config.action_cable.url = "wss://example.com/cable" + # config.action_cable.allowed_request_origins = [ "http://example.com", /http:\/\/example.*/ ] + + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. + # config.force_ssl = true + + # Include generic and useful information about system operation, but avoid logging too much + # information to avoid inadvertent exposure of personally identifiable information (PII). + config.log_level = :info + + # Prepend all log lines with the following tags. + config.log_tags = [ :request_id ] + + # Use a different cache store in production. + # config.cache_store = :mem_cache_store + + # Use a real queuing backend for Active Job (and separate queues per environment). + # config.active_job.queue_adapter = :resque + # config.active_job.queue_name_prefix = "quick_start_api_production" + + config.action_mailer.perform_caching = false + + # Ignore bad email addresses and do not raise email delivery errors. + # Set this to true and configure the email server for immediate delivery to raise delivery errors. + # config.action_mailer.raise_delivery_errors = false + + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation cannot be found). + config.i18n.fallbacks = true + + # Don't log any deprecations. + config.active_support.report_deprecations = false + + # Use default logging formatter so that PID and timestamp are not suppressed. + config.log_formatter = ::Logger::Formatter.new + + # Use a different logger for distributed setups. + # require "syslog/logger" + # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new "app-name") + + if ENV["RAILS_LOG_TO_STDOUT"].present? + logger = ActiveSupport::Logger.new(STDOUT) + logger.formatter = config.log_formatter + config.logger = ActiveSupport::TaggedLogging.new(logger) + end + + # Do not dump schema after migrations. + config.active_record.dump_schema_after_migration = false + + # Validate hosts that can access this API + config.hosts = [ + IPAddr.new("0.0.0.0/0"), # All IPv4 addresses. + IPAddr.new("::/0"), # All IPv6 addresses. + "localhost", # The localhost reserved domain. + "app", # The internal docker reserved domain. + ENV["RAILS_DEVELOPMENT_HOSTS"] # Additional comma-separated hosts for development. + ] +end diff --git a/examples/datadog-propagation/quick_start_api_otel/config/environments/test.rb b/examples/datadog-propagation/quick_start_api_otel/config/environments/test.rb new file mode 100644 index 0000000000..6ea4d1e706 --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_otel/config/environments/test.rb @@ -0,0 +1,60 @@ +require "active_support/core_ext/integer/time" + +# The test environment is used exclusively to run your application's +# test suite. You never need to work with it otherwise. Remember that +# your test database is "scratch space" for the test suite and is wiped +# and recreated between test runs. Don't rely on the data there! + +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # Turn false under Spring and add config.action_view.cache_template_loading = true. + config.cache_classes = true + + # Eager loading loads your whole application. When running a single test locally, + # this probably isn't necessary. It's a good idea to do in a continuous integration + # system, or in some way before deploying your code. + config.eager_load = ENV["CI"].present? + + # Configure public file server for tests with Cache-Control for performance. + config.public_file_server.enabled = true + config.public_file_server.headers = { + "Cache-Control" => "public, max-age=#{1.hour.to_i}" + } + + # Show full error reports and disable caching. + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + config.cache_store = :null_store + + # Raise exceptions instead of rendering exception templates. + config.action_dispatch.show_exceptions = false + + # Disable request forgery protection in test environment. + config.action_controller.allow_forgery_protection = false + + # Store uploaded files on the local file system in a temporary directory. + config.active_storage.service = :test + + config.action_mailer.perform_caching = false + + # Tell Action Mailer not to deliver emails to the real world. + # The :test delivery method accumulates sent emails in the + # ActionMailer::Base.deliveries array. + config.action_mailer.delivery_method = :test + + # Print deprecation notices to the stderr. + config.active_support.deprecation = :stderr + + # Raise exceptions for disallowed deprecations. + config.active_support.disallowed_deprecation = :raise + + # Tell Active Support which deprecation messages to disallow. + config.active_support.disallowed_deprecation_warnings = [] + + # Raises error for missing translations. + # config.i18n.raise_on_missing_translations = true + + # Annotate rendered view with file names. + # config.action_view.annotate_rendered_view_with_filenames = true +end diff --git a/examples/datadog-propagation/quick_start_api_otel/config/initializers/cors.rb b/examples/datadog-propagation/quick_start_api_otel/config/initializers/cors.rb new file mode 100644 index 0000000000..e5a82f162c --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_otel/config/initializers/cors.rb @@ -0,0 +1,16 @@ +# Be sure to restart your server when you modify this file. + +# Avoid CORS issues when API is called from the frontend app. +# Handle Cross-Origin Resource Sharing (CORS) in order to accept cross-origin AJAX requests. + +# Read more: https://github.com/cyu/rack-cors + +# Rails.application.config.middleware.insert_before 0, Rack::Cors do +# allow do +# origins "example.com" +# +# resource "*", +# headers: :any, +# methods: [:get, :post, :put, :patch, :delete, :options, :head] +# end +# end diff --git a/examples/datadog-propagation/quick_start_api_otel/config/initializers/filter_parameter_logging.rb b/examples/datadog-propagation/quick_start_api_otel/config/initializers/filter_parameter_logging.rb new file mode 100644 index 0000000000..adc6568ce8 --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_otel/config/initializers/filter_parameter_logging.rb @@ -0,0 +1,8 @@ +# Be sure to restart your server when you modify this file. + +# Configure parameters to be filtered from the log file. Use this to limit dissemination of +# sensitive information. See the ActiveSupport::ParameterFilter documentation for supported +# notations and behaviors. +Rails.application.config.filter_parameters += [ + :passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn +] diff --git a/examples/datadog-propagation/quick_start_api_otel/config/initializers/inflections.rb b/examples/datadog-propagation/quick_start_api_otel/config/initializers/inflections.rb new file mode 100644 index 0000000000..3860f659ea --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_otel/config/initializers/inflections.rb @@ -0,0 +1,16 @@ +# Be sure to restart your server when you modify this file. + +# Add new inflection rules using the following format. Inflections +# are locale specific, and you may define rules for as many different +# locales as you wish. All of these examples are active by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.plural /^(ox)$/i, "\\1en" +# inflect.singular /^(ox)en/i, "\\1" +# inflect.irregular "person", "people" +# inflect.uncountable %w( fish sheep ) +# end + +# These inflection rules are supported but not enabled by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.acronym "RESTful" +# end diff --git a/examples/datadog-propagation/quick_start_api_otel/config/initializers/open_telemetry.rb b/examples/datadog-propagation/quick_start_api_otel/config/initializers/open_telemetry.rb new file mode 100644 index 0000000000..51fa9c76fd --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_otel/config/initializers/open_telemetry.rb @@ -0,0 +1,8 @@ +require 'opentelemetry/sdk' +require 'opentelemetry/exporter/otlp' +require 'opentelemetry/instrumentation/all' + +OpenTelemetry::SDK.configure do |c| + c.service_name = ENV['SERVICE_NAME'] + c.use_all() # enables all instrumentation! +end diff --git a/examples/datadog-propagation/quick_start_api_otel/config/locales/en.yml b/examples/datadog-propagation/quick_start_api_otel/config/locales/en.yml new file mode 100644 index 0000000000..8ca56fc74f --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_otel/config/locales/en.yml @@ -0,0 +1,33 @@ +# Files in the config/locales directory are used for internationalization +# and are automatically loaded by Rails. If you want to use locales other +# than English, add the necessary files in this directory. +# +# To use the locales, use `I18n.t`: +# +# I18n.t "hello" +# +# In views, this is aliased to just `t`: +# +# <%= t("hello") %> +# +# To use a different locale, set it with `I18n.locale`: +# +# I18n.locale = :es +# +# This would use the information in config/locales/es.yml. +# +# The following keys must be escaped otherwise they will not be retrieved by +# the default I18n backend: +# +# true, false, on, off, yes, no +# +# Instead, surround them with single quotes. +# +# en: +# "true": "foo" +# +# To learn more, please read the Rails Internationalization guide +# available at https://guides.rubyonrails.org/i18n.html. + +en: + hello: "Hello world" diff --git a/examples/datadog-propagation/quick_start_api_otel/config/puma.rb b/examples/datadog-propagation/quick_start_api_otel/config/puma.rb new file mode 100644 index 0000000000..daaf036999 --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_otel/config/puma.rb @@ -0,0 +1,43 @@ +# Puma can serve each request in a thread from an internal thread pool. +# The `threads` method setting takes two numbers: a minimum and maximum. +# Any libraries that use thread pools should be configured to match +# the maximum value specified for Puma. Default is set to 5 threads for minimum +# and maximum; this matches the default thread size of Active Record. +# +max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } +min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count } +threads min_threads_count, max_threads_count + +# Specifies the `worker_timeout` threshold that Puma will use to wait before +# terminating a worker in development environments. +# +worker_timeout 3600 if ENV.fetch("RAILS_ENV", "development") == "development" + +# Specifies the `port` that Puma will listen on to receive requests; default is 3000. +# +port ENV.fetch("PORT") { 3000 } + +# Specifies the `environment` that Puma will run in. +# +environment ENV.fetch("RAILS_ENV") { "development" } + +# Specifies the `pidfile` that Puma will use. +pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" } + +# Specifies the number of `workers` to boot in clustered mode. +# Workers are forked web server processes. If using threads and workers together +# the concurrency of the application would be max `threads` * `workers`. +# Workers do not work on JRuby or Windows (both of which do not support +# processes). +# +# workers ENV.fetch("WEB_CONCURRENCY") { 2 } + +# Use the `preload_app!` method when specifying a `workers` number. +# This directive tells Puma to first boot the application and load code +# before forking the application. This takes advantage of Copy On Write +# process behavior so workers use less memory. +# +# preload_app! + +# Allow puma to be restarted by `bin/rails restart` command. +plugin :tmp_restart diff --git a/examples/datadog-propagation/quick_start_api_otel/config/routes.rb b/examples/datadog-propagation/quick_start_api_otel/config/routes.rb new file mode 100644 index 0000000000..90f773f9ff --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_otel/config/routes.rb @@ -0,0 +1,5 @@ +Rails.application.routes.draw do + get '/hello', to: 'hello#local_hello' + + get '/remotehello', to: 'hello#remote_hello' +end diff --git a/examples/datadog-propagation/quick_start_api_otel/config/storage.yml b/examples/datadog-propagation/quick_start_api_otel/config/storage.yml new file mode 100644 index 0000000000..4942ab6694 --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_otel/config/storage.yml @@ -0,0 +1,34 @@ +test: + service: Disk + root: <%= Rails.root.join("tmp/storage") %> + +local: + service: Disk + root: <%= Rails.root.join("storage") %> + +# Use bin/rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key) +# amazon: +# service: S3 +# access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %> +# secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %> +# region: us-east-1 +# bucket: your_own_bucket-<%= Rails.env %> + +# Remember not to checkin your GCS keyfile to a repository +# google: +# service: GCS +# project: your_project +# credentials: <%= Rails.root.join("path/to/gcs.keyfile") %> +# bucket: your_own_bucket-<%= Rails.env %> + +# Use bin/rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key) +# microsoft: +# service: AzureStorage +# storage_account_name: your_account_name +# storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %> +# container: your_container_name-<%= Rails.env %> + +# mirror: +# service: Mirror +# primary: local +# mirrors: [ amazon, google, microsoft ] diff --git a/examples/datadog-propagation/quick_start_api_otel/db/seeds.rb b/examples/datadog-propagation/quick_start_api_otel/db/seeds.rb new file mode 100644 index 0000000000..bc25fce306 --- /dev/null +++ b/examples/datadog-propagation/quick_start_api_otel/db/seeds.rb @@ -0,0 +1,7 @@ +# This file should contain all the record creation needed to seed the database with its default values. +# The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup). +# +# Examples: +# +# movies = Movie.create([{ name: "Star Wars" }, { name: "Lord of the Rings" }]) +# Character.create(name: "Luke", movie: movies.first) diff --git a/examples/datadog-propagation/tracebased-tests/datadog_instrumented_api_to_otel_sdk_instrumented_api.yaml b/examples/datadog-propagation/tracebased-tests/datadog_instrumented_api_to_otel_sdk_instrumented_api.yaml new file mode 100644 index 0000000000..9e1148b4ad --- /dev/null +++ b/examples/datadog-propagation/tracebased-tests/datadog_instrumented_api_to_otel_sdk_instrumented_api.yaml @@ -0,0 +1,12 @@ +type: Test +spec: + id: ZYIhp_xSR + name: Datadog-instrumented API to OTelSDK-instrumented API + trigger: + type: http + httpRequest: + method: GET + url: http://api-datadog:8080/remotehello + headers: + - key: Content-Type + value: application/json diff --git a/examples/datadog-propagation/tracebased-tests/otel_sdk_instrumented_api_to_datadog_instrumented_api.yaml b/examples/datadog-propagation/tracebased-tests/otel_sdk_instrumented_api_to_datadog_instrumented_api.yaml new file mode 100644 index 0000000000..059bdb11b6 --- /dev/null +++ b/examples/datadog-propagation/tracebased-tests/otel_sdk_instrumented_api_to_datadog_instrumented_api.yaml @@ -0,0 +1,12 @@ +type: Test +spec: + id: CdhJp_xIR + name: OTelSDK-instrumented API to Datadog-instrumented API + trigger: + type: http + httpRequest: + method: GET + url: http://api-otel:8080/remotehello + headers: + - key: Content-Type + value: application/json