Last active
March 28, 2023 08:42
-
-
Save bamorim/5e1d9a4bc41121c4475c2ecdcc2736fc to your computer and use it in GitHub Desktop.
Opentelemetry Span <> Logger integration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Config | |
config :opentelemetry, | |
processors: [ | |
{OpentelemetrySpanLogger, []}, | |
:batch | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule OpentelemetrySpanLogger do | |
require Record | |
@behaviour :otel_span_processor | |
@span_record Record.extract(:span, from_lib: "opentelemetry/include/otel_span.hrl") | |
Record.defrecord(:span, @span_record) | |
@impl :otel_span_processor | |
def force_flush(_config), do: :ok | |
@impl :otel_span_processor | |
def on_start(_ctx, span, _config) do | |
Logger.metadata([trace_id: span(span, :trace_id), span_id: span(span, :span_id)]) | |
span | |
end | |
@impl :otel_span_processor | |
def on_end(_span, _config), do: true | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment