-
-
Notifications
You must be signed in to change notification settings - Fork 200
Support for Traces/Transactions via Opentelemetry #784
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
53 commits
Select commit
Hold shift + click to select a range
ec16ca8
Support configurable DSN for phoenix test app
solnic f214b82
Initial work on OTel-based Transactions
solnic 59f0c2b
Move SpanStorage to its own file
solnic 025ec6e
Rename Sentry.Telemetry => Sentry.Opentelemetry
solnic f7fb086
Introduce SpanRecord to simplify processing
solnic ab82965
Move casting trace_id to the SpanRecord struct
solnic e953b26
Move casting of span ids to the SpanRecord struct
solnic 2d97073
No need to pass trace_id around anymore
solnic 91ef16f
Handle casting timestamps in the SpanRecord struct
solnic 4f2e63b
Extract SpanRecord into its own file
solnic 6e19f48
Remove redundant function
solnic fca71df
Move setting platform info to the Client
solnic 2f62ce7
Extract setting root span context
solnic fc91ca7
Improve ecto span/transaction
solnic a79dbc3
Unify top-level ecto transactions and ecto spans
solnic e9b6ef5
Return full URL and status info in Phoenix transactions
solnic b8c0c86
Fix extracting span record when sentry is an external dep
solnic 5883053
Support for liveview traces/spans
solnic 3155116
Remove span records after sending a transaction
solnic d2e3669
Fix formatting
solnic 23f7122
Fix formatting
solnic 83180e6
Fix dialyzer warnings
solnic 770c67e
More dialyzer fixes
solnic 8d9e81d
Fix build for 1.16
solnic 8bab636
Remove debugging statement
solnic 72c7d98
Update lib/sentry/opentelemetry/span_processor.ex
solnic 7061f3c
WIP - rework SpanStorage to use ETS
solnic 631b824
Refactor span storage (#817)
savhappy 3dd1a94
Add tests for Sentry.send_transaction
solnic aa9f5f5
Opentelemetry => OpenTelemetry
solnic 6301fe5
Use SpanStorage alias in the test
solnic 3e93cfa
Tests for SpanStorage
solnic b7eb637
Remove child spans from SpanStorage automatically
solnic 70f8e61
Add sweeping of expired spans
solnic 54d1f20
Make opentelemetry libs optional deps
solnic 6788ad5
Fix tests under 1.13
solnic 7b2fc02
Support Transaction in client reports
solnic 4f3ada1
wip - initial work on oban support
solnic 1856faa
wip - add a UI for testing Oban workers
solnic 6c2d80c
Refactor OTel (#835)
danschultzer b7b1dc6
Update dep specs for opentelemetry_*
solnic 10224eb
[tmp] use opentelemetry_oban from git
solnic f67446e
Fix warning in get_op_description
solnic 4a175a9
Fix formatting
solnic d2f88a2
Refine how we set values for Oban jobs
solnic 469b5cd
Extend the test worker UI with auto-scheduling
solnic 9c59d36
Filter out Oban internal traces
solnic 0832054
Oops, fix filtering Oban Stager spans
solnic 01fcd87
Address dialyzer warning (I think)
solnic 4c32d87
Set sdk version dynamically
solnic 9b4d700
Fix client report data category for transactions
solnic 7ad38bb
Add Sentry's Sampler for OTel
solnic a808377
Remove conditional we longer need
solnic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 | ||
---|---|---|---|---|
|
@@ -16,7 +16,8 @@ defmodule Sentry.Client do | |||
Interfaces, | ||||
LoggerUtils, | ||||
Transport, | ||||
Options | ||||
Options, | ||||
Transaction | ||||
} | ||||
|
||||
require Logger | ||||
|
@@ -107,6 +108,26 @@ defmodule Sentry.Client do | |||
|> Transport.encode_and_post_envelope(client, request_retries) | ||||
end | ||||
|
||||
def send_transaction(%Transaction{} = transaction, opts \\ []) do | ||||
# opts = validate_options!(opts) | ||||
|
||||
Comment on lines
+112
to
+113
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
result_type = Keyword.get_lazy(opts, :result, &Config.send_result/0) | ||||
client = Keyword.get_lazy(opts, :client, &Config.client/0) | ||||
|
||||
request_retries = | ||||
Keyword.get_lazy(opts, :request_retries, fn -> | ||||
Application.get_env(:sentry, :request_retries, Transport.default_retries()) | ||||
end) | ||||
|
||||
case encode_and_send(transaction, result_type, client, request_retries) do | ||||
{:ok, id} -> | ||||
{:ok, id} | ||||
|
||||
{:error, %ClientError{} = error} -> | ||||
{:error, error} | ||||
end | ||||
end | ||||
|
||||
defp sample_event(sample_rate) do | ||||
cond do | ||||
sample_rate == 1 -> :ok | ||||
|
@@ -205,6 +226,42 @@ defmodule Sentry.Client do | |||
end | ||||
end | ||||
|
||||
defp encode_and_send( | ||||
%Transaction{} = transaction, | ||||
_result_type = :sync, | ||||
client, | ||||
request_retries | ||||
) do | ||||
case Sentry.Test.maybe_collect(transaction) do | ||||
:collected -> | ||||
{:ok, ""} | ||||
|
||||
:not_collecting -> | ||||
send_result = | ||||
transaction | ||||
|> Envelope.from_transaction() | ||||
|> Transport.encode_and_post_envelope(client, request_retries) | ||||
|
||||
send_result | ||||
end | ||||
end | ||||
|
||||
defp encode_and_send( | ||||
%Transaction{} = transaction, | ||||
_result_type = :none, | ||||
client, | ||||
_request_retries | ||||
) do | ||||
case Sentry.Test.maybe_collect(transaction) do | ||||
:collected -> | ||||
{:ok, ""} | ||||
|
||||
:not_collecting -> | ||||
:ok = Transport.Sender.send_async(client, transaction) | ||||
{:ok, ""} | ||||
end | ||||
end | ||||
|
||||
@spec render_event(Event.t()) :: map() | ||||
def render_event(%Event{} = event) do | ||||
json_library = Config.json_library() | ||||
|
@@ -225,6 +282,19 @@ defmodule Sentry.Client do | |||
|> update_if_present(:threads, fn list -> Enum.map(list, &render_thread/1) end) | ||||
end | ||||
|
||||
@spec render_transaction(%Transaction{}) :: map() | ||||
def render_transaction(%Transaction{} = transaction) do | ||||
transaction | ||||
|> Transaction.to_map() | ||||
|> Map.merge(%{ | ||||
platform: "elixir", | ||||
sdk: %{ | ||||
name: "sentry.elixir", | ||||
version: Application.spec(:sentry, :vsn) | ||||
} | ||||
}) | ||||
end | ||||
|
||||
defp render_exception(%Interfaces.Exception{} = exception) do | ||||
exception | ||||
|> Map.from_struct() | ||||
|
This file contains hidden or 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 hidden or 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,27 @@ | ||
defmodule Sentry.OpenTelemetry.Sampler do | ||
@moduledoc false | ||
|
||
def setup(config) do | ||
config | ||
end | ||
|
||
def description(_) do | ||
"SentrySampler" | ||
end | ||
|
||
def should_sample( | ||
_ctx, | ||
_trace_id, | ||
_links, | ||
span_name, | ||
_span_kind, | ||
_attributes, | ||
config | ||
) do | ||
if span_name in config[:drop] do | ||
{:drop, [], []} | ||
else | ||
{:record_and_sample, [], []} | ||
end | ||
end | ||
end |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@whatyouhide seems like this just doesn't do anything under Elixir 1.13 - do you maybe have any insights here? What would be an equivalent of this for older Elixir?