Skip to content

Commit f7113fe

Browse files
committed
Initialize OpenTelemetry SDK and setup automatic instrumentations
- Setup Cowboy HTTP server instrumentation with correct Erlang module syntax - Configure Phoenix instrumentation with cowboy2 adapter specification - Initialize Ecto database query instrumentation - Setup Absinthe GraphQL operation instrumentation - Add startup logging for configuration verification - Instrumentations initialized before application starts accepting requests
1 parent e45ee70 commit f7113fe

File tree

1 file changed

+20
-0
lines changed
  • manual-instrumentation/worms_in_space/lib/worms_in_space

1 file changed

+20
-0
lines changed

manual-instrumentation/worms_in_space/lib/worms_in_space/application.ex

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ defmodule WormsInSpace.Application do
77

88
@impl true
99
def start(_type, _args) do
10+
# Setup OpenTelemetry instrumentations
11+
setup_opentelemetry()
12+
1013
children = [
1114
# Start the Ecto repository
1215
WormsInSpace.Repo,
@@ -24,6 +27,23 @@ defmodule WormsInSpace.Application do
2427
Supervisor.start_link(children, opts)
2528
end
2629

30+
defp setup_opentelemetry do
31+
# Setup OpenTelemetry SDK
32+
:opentelemetry_cowboy.setup()
33+
OpentelemetryPhoenix.setup(adapter: :cowboy2)
34+
OpentelemetryEcto.setup([:worms_in_space, :repo])
35+
OpentelemetryAbsinthe.setup()
36+
37+
# Log initialization status
38+
if System.get_env("SPLUNK_ACCESS_TOKEN") do
39+
service_name = System.get_env("OTEL_SERVICE_NAME", "worms-in-space-backend")
40+
realm = System.get_env("SPLUNK_REALM", "us0")
41+
IO.puts("OpenTelemetry initialized for #{service_name} sending to Splunk #{realm}")
42+
else
43+
IO.puts("OpenTelemetry: No Splunk access token configured. Traces will not be sent.")
44+
end
45+
end
46+
2747
# Tell Phoenix to update the endpoint configuration
2848
# whenever the application is updated.
2949
@impl true

0 commit comments

Comments
 (0)