-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
189fe09
commit d13b509
Showing
7 changed files
with
169 additions
and
14 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
defmodule OpentelemetryAbsinthe.TelemetryMetadata do | ||
@moduledoc """ | ||
A helper module to allow integrators to add custom data to their context | ||
which will then be added to the [:opentelemetry_absinthe, :graphql, :handled] | ||
event | ||
""" | ||
@key __MODULE__ | ||
|
||
@type absinthe_context :: map() | ||
@type telemetry_metadata :: %{ | ||
optional(atom()) => any() | ||
} | ||
|
||
@spec update_context(absinthe_context(), telemetry_metadata()) :: absinthe_context() | ||
def update_context(%{} = context, %{} = metadata), | ||
do: Map.update(context, @key, metadata, &Map.merge(&1, metadata)) | ||
|
||
@spec from_context(absinthe_context()) :: telemetry_metadata() | ||
def from_context(%{} = context), do: Map.get(context, @key, %{}) | ||
end |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
defmodule BlueprintArchitect do | ||
@moduledoc false | ||
|
||
alias Absinthe.Blueprint | ||
|
||
@spec blueprint(keyword()) :: Blueprint.t() | ||
def blueprint(overrides \\ []) do | ||
%{ | ||
operations: [operation()] | ||
} | ||
|> Map.merge(Enum.into(overrides, %{})) | ||
|> then(&struct!(Blueprint, &1)) | ||
end | ||
|
||
@spec operation(keyword()) :: Blueprint.Document.Operation.t() | ||
def operation(overrides \\ []) do | ||
%{ | ||
name: "TestOperation", | ||
type: :query, | ||
current: true | ||
} | ||
|> Map.merge(Enum.into(overrides, %{})) | ||
|> then(&struct!(Blueprint.Document.Operation, &1)) | ||
end | ||
|
||
@spec execution(keyword()) :: Blueprint.Execution.t() | ||
def execution(overrides \\ []) do | ||
%{} | ||
|> Map.merge(Enum.into(overrides, %{})) | ||
|> then(&struct!(Blueprint.Execution, &1)) | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
defmodule OpentelemetryAbsinthe.TelemetryMetadataTest do | ||
use ExUnit.Case | ||
|
||
alias OpentelemetryAbsinthe.TelemetryMetadata | ||
|
||
test "should return an empty metadata when context is empty" do | ||
assert %{} == TelemetryMetadata.from_context(%{}) | ||
end | ||
|
||
test "should return an empty metadata when context does not contain metadata" do | ||
assert %{} == TelemetryMetadata.from_context(%{foo: :bar}) | ||
end | ||
|
||
test "should return same metadata that was stored" do | ||
assert %{user_agent: :test} == | ||
%{} | ||
|> TelemetryMetadata.update_context(%{user_agent: :test}) | ||
|> TelemetryMetadata.from_context() | ||
end | ||
end |