Skip to content

Commit

Permalink
Merge branch 'main' into chore/run-propagator-dialyzer-on-ci
Browse files Browse the repository at this point in the history
  • Loading branch information
joaothallis authored Oct 26, 2023
2 parents 0729f0c + e62612f commit b4df8da
Show file tree
Hide file tree
Showing 23 changed files with 93 additions and 47 deletions.
3 changes: 1 addition & 2 deletions .github/release-drafter-templates/opentelemetry-aws-xray.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ name-template: 'Opentelemetry AWS X-Ray - v$RESOLVED_VERSION'
tag-template: 'opentelemetry-aws-xray-v$RESOLVED_VERSION'
tag-prefix: opentelemetry-aws-xray-v
include-paths:
- utilities/opentelemetry_aws_xray/src/**/*
- utilities/opentelemetry_aws_xray/rebar.*
- utilities/opentelemetry_aws_xray/
3 changes: 1 addition & 2 deletions .github/release-drafter-templates/opentelemetry-cowboy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ name-template: 'Opentelemetry Cowboy - v$RESOLVED_VERSION'
tag-template: 'opentelemetry-cowboy-v$RESOLVED_VERSION'
tag-prefix: opentelemetry-cowboy-v
include-paths:
- instrumentation/opentelemetry_cowboy/src/**/*
- instrumentation/opentelemetry_cowboy/rebar.*
- instrumentation/opentelemetry_cowboy/
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ name-template: 'Opentelemetry Dataloader - v$RESOLVED_VERSION'
tag-template: 'opentelemetry-dataloader-v$RESOLVED_VERSION'
tag-prefix: opentelemetry-dataloader-v
include-paths:
- instrumentation/opentelemetry_dataloader/lib/**/*
- instrumentation/opentelemetry_dataloader/lib/mix.*
- instrumentation/opentelemetry_dataloader/
3 changes: 1 addition & 2 deletions .github/release-drafter-templates/opentelemetry-ecto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ name-template: 'Opentelemetry Ecto - v$RESOLVED_VERSION'
tag-template: 'opentelemetry-ecto-v$RESOLVED_VERSION'
tag-prefix: opentelemetry-ecto-v
include-paths:
- instrumentation/opentelemetry_ecto/lib/**/*
- instrumentation/opentelemetry_ecto/lib/mix.*
- instrumentation/opentelemetry_ecto/
3 changes: 1 addition & 2 deletions .github/release-drafter-templates/opentelemetry-elli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ name-template: 'Opentelemetry Elli - v$RESOLVED_VERSION'
tag-template: 'opentelemetry-elli-v$RESOLVED_VERSION'
tag-prefix: opentelemetry-elli-v
include-paths:
- instrumentation/opentelemetry_elli/src/**/*
- instrumentation/opentelemetry_elli/rebar.*
- instrumentation/opentelemetry_elli/
3 changes: 1 addition & 2 deletions .github/release-drafter-templates/opentelemetry-finch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ name-template: 'Opentelemetry Finch - v$RESOLVED_VERSION'
tag-template: 'opentelemetry-finch-v$RESOLVED_VERSION'
tag-prefix: opentelemetry-finch-v
include-paths:
- instrumentation/opentelemetry_finch/lib/**/*
- instrumentation/opentelemetry_finch/lib/mix.*
- instrumentation/opentelemetry_finch/
3 changes: 1 addition & 2 deletions .github/release-drafter-templates/opentelemetry-grpcbox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ name-template: 'Opentelemetry GRPCBox - v$RESOLVED_VERSION'
tag-template: 'opentelemetry-grpcbox-v$RESOLVED_VERSION'
tag-prefix: opentelemetry-grpcbox-v
include-paths:
- instrumentation/opentelemetry_grpcbox/src/**/*
- instrumentation/opentelemetry_grpcbox/rebar.*
- instrumentation/opentelemetry_grpcbox/
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ name-template: 'Opentelemetry HTTPoison - v$RESOLVED_VERSION'
tag-template: 'opentelemetry-httpoison-v$RESOLVED_VERSION'
tag-prefix: opentelemetry-httpoison-v
include-paths:
- instrumentation/opentelemetry_httpoison/lib/**/*
- instrumentation/opentelemetry_httpoison/lib/mix.*
- instrumentation/opentelemetry_httpoison/
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ name-template: 'Opentelemetry Instrumentation HTTP - v$RESOLVED_VERSION'
tag-template: 'opentelemetry-instrumentation-http-v$RESOLVED_VERSION'
tag-prefix: opentelemetry-instrumentation-http-v
include-paths:
- utilities/opentelemetry_instrumentation-http/src/**/*
- utilities/opentelemetry_instrumentation-http/rebar.*
- utilities/opentelemetry_instrumentation-http/
3 changes: 1 addition & 2 deletions .github/release-drafter-templates/opentelemetry-nebulex.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ name-template: 'Opentelemetry Nebulex - v$RESOLVED_VERSION'
tag-template: 'opentelemetry-nebulex-v$RESOLVED_VERSION'
tag-prefix: opentelemetry-nebulex-v
include-paths:
- instrumentation/opentelemetry_nebulex/lib/**/*
- instrumentation/opentelemetry_nebulex/lib/mix.*
- instrumentation/opentelemetry_nebulex/
3 changes: 1 addition & 2 deletions .github/release-drafter-templates/opentelemetry-oban.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ name-template: 'Opentelemetry Oban - v$RESOLVED_VERSION'
tag-template: 'opentelemetry-oban-v$RESOLVED_VERSION'
tag-prefix: opentelemetry-oban-v
include-paths:
- instrumentation/opentelemetry_oban/lib/**/*
- instrumentation/opentelemetry_oban/lib/mix.*
- instrumentation/opentelemetry_oban/
3 changes: 1 addition & 2 deletions .github/release-drafter-templates/opentelemetry-phoenix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ name-template: 'Opentelemetry Phoenix - v$RESOLVED_VERSION'
tag-template: 'opentelemetry-phoenix-v$RESOLVED_VERSION'
tag-prefix: opentelemetry-phoenix-v
include-paths:
- instrumentation/opentelemetry_phoenix/lib/**/*
- instrumentation/opentelemetry_phoenix/lib/mix.*
- instrumentation/opentelemetry_phoenix/
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,4 @@ name-template: 'Opentelemetry Process Propagator - v$RESOLVED_VERSION'
tag-template: 'opentelemetry-process-propagator-v$RESOLVED_VERSION'
tag-prefix: opentelemetry-process-propagator-v
include-paths:
- propagators/opentelemetry_process_propagator/src/**/*
- propagators/opentelemetry_process_propagator/rebar.*
- propagators/opentelemetry_process_propagator/lib/**/*
- propagators/opentelemetry_process_propagator/lib/mix.*
- propagators/opentelemetry_process_propagator/
3 changes: 1 addition & 2 deletions .github/release-drafter-templates/opentelemetry-redix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ name-template: 'Opentelemetry Redix - v$RESOLVED_VERSION'
tag-template: 'opentelemetry-redix-v$RESOLVED_VERSION'
tag-prefix: opentelemetry-redix-v
include-paths:
- instrumentation/opentelemetry_redix/lib/**/*
- instrumentation/opentelemetry_redix/lib/mix.*
- instrumentation/opentelemetry_redix/
3 changes: 1 addition & 2 deletions .github/release-drafter-templates/opentelemetry-req.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ name-template: 'Opentelemetry Req - v$RESOLVED_VERSION'
tag-template: 'opentelemetry-req-v$RESOLVED_VERSION'
tag-prefix: opentelemetry-req-v
include-paths:
- instrumentation/opentelemetry_req/lib/**/*
- instrumentation/opentelemetry_req/lib/mix.*
- instrumentation/opentelemetry_req/
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,4 @@ name-template: 'Opentelemetry Telemetry - v$RESOLVED_VERSION'
tag-template: 'opentelemetry-telemetry-v$RESOLVED_VERSION'
tag-prefix: opentelemetry-telemetry-v
include-paths:
- utilities/opentelemetry_telemetry/src/**/*
- utilities/opentelemetry_telemetry/rebar.*
- utilities/opentelemetry_telemetry/lib/**/*
- utilities/opentelemetry_telemetry/lib/mix.*
- utilities/opentelemetry_telemetry/
3 changes: 1 addition & 2 deletions .github/release-drafter-templates/opentelemetry-tesla.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ name-template: 'Opentelemetry Tesla - v$RESOLVED_VERSION'
tag-template: 'opentelemetry-tesla-v$RESOLVED_VERSION'
tag-prefix: opentelemetry-tesla-v
include-paths:
- instrumentation/opentelemetry_tesla/lib/**/*
- instrumentation/opentelemetry_tesla/lib/mix.*
- instrumentation/opentelemetry_tesla/
11 changes: 8 additions & 3 deletions instrumentation/opentelemetry_req/lib/opentelemetry_req.ex
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ defmodule OpentelemetryReq do
method = http_method(request.method)

case Req.Request.get_private(request, :path_params_template) do
nil -> method
params_template -> "#{method} #{params_template}"
nil -> "HTTP #{method}"
params_template -> "#{params_template}"
end

span_name ->
Expand Down Expand Up @@ -202,7 +202,12 @@ defmodule OpentelemetryReq do

defp maybe_put_trace_headers(request) do
if request.options[:propagate_trace_ctx] do
Map.put(request, :headers, :otel_propagator_text_map.inject(request.headers))
propagator = :opentelemetry.get_text_map_injector()
headers_to_inject = :otel_propagator_text_map.inject(propagator, [], &[{&1, &2} | &3])

Enum.reduce(headers_to_inject, request, fn {name, value}, acc ->
Req.Request.put_header(acc, name, value)
end)
else
request
end
Expand Down
3 changes: 2 additions & 1 deletion instrumentation/opentelemetry_req/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ defmodule OpentelemetryReq.MixProject do
{:opentelemetry_api, "~> 1.0"},
{:opentelemetry_semantic_conventions, "~> 0.2"},
{:req, ">= 0.3.5"},
{:ex_doc, "~> 0.29", only: [:dev, :test]}
{:ex_doc, "~> 0.29", only: [:dev, :test]},
{:opentelemetry, "~> 1.0", only: :test}
]
end
end
1 change: 1 addition & 0 deletions instrumentation/opentelemetry_req/mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"nimble_options": {:hex, :nimble_options, "0.5.2", "42703307b924880f8c08d97719da7472673391905f528259915782bb346e0a1b", [:mix], [], "hexpm", "4da7f904b915fd71db549bcdc25f8d56f378ef7ae07dc1d372cbe72ba950dce0"},
"nimble_parsec": {:hex, :nimble_parsec, "1.2.3", "244836e6e3f1200c7f30cb56733fd808744eca61fd182f731eac4af635cc6d0b", [:mix], [], "hexpm", "c8d789e39b9131acf7b99291e93dae60ab48ef14a7ee9d58c6964f59efb570b0"},
"nimble_pool": {:hex, :nimble_pool, "0.2.6", "91f2f4c357da4c4a0a548286c84a3a28004f68f05609b4534526871a22053cde", [:mix], [], "hexpm", "1c715055095d3f2705c4e236c18b618420a35490da94149ff8b580a2144f653f"},
"opentelemetry": {:hex, :opentelemetry, "1.3.0", "988ac3c26acac9720a1d4fb8d9dc52e95b45ecfec2d5b5583276a09e8936bc5e", [:rebar3], [{:opentelemetry_api, "~> 1.2.0", [hex: :opentelemetry_api, repo: "hexpm", optional: false]}, {:opentelemetry_semantic_conventions, "~> 0.2", [hex: :opentelemetry_semantic_conventions, repo: "hexpm", optional: false]}], "hexpm", "8e09edc26aad11161509d7ecad854a3285d88580f93b63b0b1cf0bac332bfcc0"},
"opentelemetry_api": {:hex, :opentelemetry_api, "1.2.1", "7b69ed4f40025c005de0b74fce8c0549625d59cb4df12d15c32fe6dc5076ff42", [:mix, :rebar3], [{:opentelemetry_semantic_conventions, "~> 0.2", [hex: :opentelemetry_semantic_conventions, repo: "hexpm", optional: false]}], "hexpm", "6d7a27b7cad2ad69a09cabf6670514cafcec717c8441beb5c96322bac3d05350"},
"opentelemetry_semantic_conventions": {:hex, :opentelemetry_semantic_conventions, "0.2.0", "b67fe459c2938fcab341cb0951c44860c62347c005ace1b50f8402576f241435", [:mix, :rebar3], [], "hexpm", "d61fa1f5639ee8668d74b527e6806e0503efc55a42db7b5f39939d84c07d6895"},
"req": {:hex, :req, "0.3.6", "541350d2cc359a8ad17059f2629c18be56d0c85ce0e4ddb27694b6ba482fe923", [:mix], [{:brotli, "~> 0.3.1", [hex: :brotli, repo: "hexpm", optional: true]}, {:ezstd, "~> 1.0", [hex: :ezstd, repo: "hexpm", optional: true]}, {:finch, "~> 0.9", [hex: :finch, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:mime, "~> 1.6 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:nimble_csv, "~> 1.0", [hex: :nimble_csv, repo: "hexpm", optional: true]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "9181047f32b05f8737f6b5917af5ee5385219158bbe4e507f4ec57791a0a78c3"},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,64 @@
defmodule OpentelemetryReqTest do
use ExUnit.Case
use ExUnit.Case, async: true
doctest OpentelemetryReq
require Record

for {name, spec} <- Record.extract_all(from_lib: "opentelemetry/include/otel_span.hrl") do
Record.defrecordp(name, spec)
end

setup do
:application.stop(:opentelemetry)
:application.set_env(:opentelemetry, :tracer, :otel_tracer_default)

:application.set_env(:opentelemetry, :processors, [
{:otel_batch_processor, %{scheduled_delay_ms: 1, exporter: {:otel_exporter_pid, self()}}}
])

:application.start(:opentelemetry)

req =
Req.new()
|> OpentelemetryReq.attach()

{:ok, req: req}
end

test "span", %{req: req} do
adapter = fn request ->
assert URI.to_string(request.url) == "/users/3"
{request, Req.Response.new(status: 204)}
end

resp =
Req.get!(req,
adapter: adapter,
url: "/users/:id",
path_params: [id: 3]
)

assert resp.status == 204
assert_receive {:span, span(name: "/users/:id")}
refute_receive _
end

test "propagate traces", %{req: req} do
adapter = fn request ->
assert [value] = Req.Request.get_header(request, "traceparent")
assert byte_size(value) > 10
{request, Req.Response.new(status: 204)}
end

resp =
Req.get!(req,
adapter: adapter,
url: "/",
no_path_params: true,
propagate_trace_ctx: true
)

assert resp.status == 204
assert_receive {:span, span()}
refute_receive _
end
end
2 changes: 1 addition & 1 deletion instrumentation/opentelemetry_tesla/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule OpentelemetryTesla.MixProject do
def project do
[
app: :opentelemetry_tesla,
version: "2.2.0",
version: "2.3.0",
elixir: "~> 1.10",
start_permanent: Mix.env() == :prod,
deps: deps(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ defmodule OpentelemetryProcessPropagator do
# you don't control, e.g. Ecto preloads
Task.async(fn ->
parent_ctx = OpentelemetryProcessPropagator.fetch_parent_ctx(:"$callers")
parent_ctx = OpentelemetryProcessPropagator.fetch_parent_ctx(1, :"$callers")
OpenTelemetry.Ctx.attach(parent_ctx)
Expand Down Expand Up @@ -82,7 +82,7 @@ defmodule OpentelemetryProcessPropagator do
"""

@doc """
Attempt to fetch an otel context from a give pid.
Attempt to fetch an otel context from a given pid.
"""
@spec fetch_ctx(pid) :: OpenTelemetry.Ctx.t() | :undefined
defdelegate fetch_ctx(pid), to: :opentelemetry_process_propagator
Expand All @@ -97,7 +97,7 @@ defmodule OpentelemetryProcessPropagator do

@doc """
Attempt to find an otel context in a spawning process within `n` number of parent
processes
processes.
"""
@spec fetch_parent_ctx(non_neg_integer()) :: OpenTelemetry.Ctx.t() | :undefined
defdelegate fetch_parent_ctx(depth), to: :opentelemetry_process_propagator
Expand Down

0 comments on commit b4df8da

Please sign in to comment.