Skip to content

Commit

Permalink
ensure no shenanigans around span juggling
Browse files Browse the repository at this point in the history
  • Loading branch information
marcdel committed Mar 18, 2024
1 parent e00adad commit 241592c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ defmodule OpenTelemetryDecorator.MixProject do
{:opentelemetry_exporter, "~> 1.7", only: :test},
{:opentelemetry_api, "~> 1.3"},
{:opentelemetry, "~> 1.4", only: :test, runtime: false},
{:o11y, path: "../o11y", override: true}
{:o11y, "~> 0.1"}
]
end

Expand Down
2 changes: 1 addition & 1 deletion mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"makeup_elixir": {:hex, :makeup_elixir, "0.16.2", "627e84b8e8bf22e60a2579dad15067c755531fea049ae26ef1020cad58fe9578", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "41193978704763f6bbe6cc2758b84909e62984c7752b3784bd3c218bb341706b"},
"makeup_erlang": {:hex, :makeup_erlang, "0.1.5", "e0ff5a7c708dda34311f7522a8758e23bfcd7d8d8068dc312b5eb41c6fd76eba", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "94d2e986428585a21516d7d7149781480013c56e30c6a233534bedf38867a59a"},
"nimble_parsec": {:hex, :nimble_parsec, "1.4.0", "51f9b613ea62cfa97b25ccc2c1b4216e81df970acd8e16e8d1bdc58fef21370d", [:mix], [], "hexpm", "9c565862810fb383e9838c1dd2d7d2c437b3d13b267414ba6af33e50d2d1cf28"},
"o11y": {:hex, :o11y, "0.1.2", "7b0be22e838f5c22313f0229571299df79779c891e6b9ec919647bb0ff8f009d", [:mix], [{:opentelemetry_api, "~> 1.2", [hex: :opentelemetry_api, repo: "hexpm", optional: false]}], "hexpm", "1c8a39351401b10ef3dd619051d4ac517dc0001c65d39f2b93c3a412d7a6d68d"},
"o11y": {:hex, :o11y, "0.1.3", "44930fc4e1edc38d09770f785481597f41093d0e7f772f2aa25221f5c8363582", [:mix], [{:opentelemetry_api, "~> 1.3", [hex: :opentelemetry_api, repo: "hexpm", optional: false]}], "hexpm", "866873fd7a5453d51c4d33ed4cf8a2d534ceae71bcc2290e4725208af015cfaf"},
"opentelemetry": {:hex, :opentelemetry, "1.4.0", "f928923ed80adb5eb7894bac22e9a198478e6a8f04020ae1d6f289fdcad0b498", [:rebar3], [{:opentelemetry_api, "~> 1.3.0", [hex: :opentelemetry_api, repo: "hexpm", optional: false]}, {:opentelemetry_semantic_conventions, "~> 0.2", [hex: :opentelemetry_semantic_conventions, repo: "hexpm", optional: false]}], "hexpm", "50b32ce127413e5d87b092b4d210a3449ea80cd8224090fe68d73d576a3faa15"},
"opentelemetry_api": {:hex, :opentelemetry_api, "1.3.0", "03e2177f28dd8d11aaa88e8522c81c2f6a788170fe52f7a65262340961e663f9", [:mix, :rebar3], [{:opentelemetry_semantic_conventions, "~> 0.2", [hex: :opentelemetry_semantic_conventions, repo: "hexpm", optional: false]}], "hexpm", "b9e5ff775fd064fa098dba3c398490b77649a352b40b0b730a6b7dc0bdd68858"},
"opentelemetry_exporter": {:hex, :opentelemetry_exporter, "1.7.0", "dec4e90c0667cf11a3642f7fe71982dbc0c6bfbb8725a0b13766830718cf0d98", [:rebar3], [{:grpcbox, ">= 0.0.0", [hex: :grpcbox, repo: "hexpm", optional: false]}, {:opentelemetry, "~> 1.4.0", [hex: :opentelemetry, repo: "hexpm", optional: false]}, {:opentelemetry_api, "~> 1.3.0", [hex: :opentelemetry_api, repo: "hexpm", optional: false]}, {:tls_certificate_check, "~> 1.18", [hex: :tls_certificate_check, repo: "hexpm", optional: false]}], "hexpm", "d0f25f6439ec43f2561537c3fabbe177b38547cddaa3a692cbb8f4770dbefc1e"},
Expand Down
33 changes: 33 additions & 0 deletions test/open_telemetry_decorator_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -257,5 +257,38 @@ defmodule OpenTelemetryDecoratorTest do
span = assert_span("Example.with_error")
%{"error" => "ruh roh!"} = span.attributes
end

test "handles current and parent span correctly" do
defmodule CurrentSpanExample do
use OpenTelemetryDecorator

@decorate with_span("CurrentSpanExample.outer")
def outer do
before_ctx = Tracer.current_span_ctx()
inner(before_ctx)
after_ctx = Tracer.current_span_ctx()

assert before_ctx == after_ctx
end

@decorate with_span("CurrentSpanExample.inner")
def inner(parent_ctx) do
assert parent_ctx != Tracer.current_span_ctx()

{:span_ctx, _, _, 1,
{:tracestate, []}, true, false, true,
{:otel_span_ets, some_fn}} = Tracer.current_span_ctx()

some_fn.(nil) |> dbg()
end
end

CurrentSpanExample.outer()

parent_span = assert_span("CurrentSpanExample.outer")
child_span = assert_span("CurrentSpanExample.inner")

assert parent_span.span_id == child_span.parent_span_id
end
end
end

0 comments on commit 241592c

Please sign in to comment.