-
-
Notifications
You must be signed in to change notification settings - Fork 188
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
Support for Traces/Transactions via Opentelemetry #784
Open
solnic
wants to merge
39
commits into
master
Choose a base branch
from
solnic/support-for-transactions-via-otel
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,504
−64
Open
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
e08210c
Support configurable DSN for phoenix test app
solnic 2ffd435
Initial work on OTel-based Transactions
solnic a7b030b
Move SpanStorage to its own file
solnic 0b84a81
Rename Sentry.Telemetry => Sentry.Opentelemetry
solnic c001d1b
Introduce SpanRecord to simplify processing
solnic ddecba0
Move casting trace_id to the SpanRecord struct
solnic 9777500
Move casting of span ids to the SpanRecord struct
solnic 4fa80f2
No need to pass trace_id around anymore
solnic f4330ec
Handle casting timestamps in the SpanRecord struct
solnic c2c0bc9
Extract SpanRecord into its own file
solnic b3dceb6
Remove redundant function
solnic 2b68f86
Move setting platform info to the Client
solnic 64d0344
Extract setting root span context
solnic e9901da
Improve ecto span/transaction
solnic b681c9a
Unify top-level ecto transactions and ecto spans
solnic 61baf6a
Return full URL and status info in Phoenix transactions
solnic e47521a
Fix extracting span record when sentry is an external dep
solnic ca1606f
Support for liveview traces/spans
solnic f0cdc22
Remove span records after sending a transaction
solnic faf9070
Fix formatting
solnic edcc9a3
Fix formatting
solnic 7e65e12
Fix dialyzer warnings
solnic b64aff5
More dialyzer fixes
solnic 3b4276a
Fix build for 1.16
solnic d166232
Remove debugging statement
solnic fe785d2
Update lib/sentry/opentelemetry/span_processor.ex
solnic 2b6a9d5
WIP - rework SpanStorage to use ETS
solnic 32ea20b
Refactor span storage (#817)
savhappy 4265136
Add tests for Sentry.send_transaction
solnic 09456d8
Opentelemetry => OpenTelemetry
solnic 5dc155c
Use SpanStorage alias in the test
solnic 75f781d
Tests for SpanStorage
solnic e2ee522
Remove child spans from SpanStorage automatically
solnic 4e8e737
Add sweeping of expired spans
solnic bf9e35f
Make opentelemetry libs optional deps
solnic 7490f9c
Fix tests under 1.13
solnic 83b0162
Support Transaction in client reports
solnic ef1b77c
wip - initial work on oban support
solnic 96d50e6
wip - add a UI for testing Oban workers
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 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
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 | ||
---|---|---|---|---|
|
@@ -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: "10.7.1" | ||||
} | ||||
}) | ||||
end | ||||
|
||||
defp render_exception(%Interfaces.Exception{} = exception) do | ||||
exception | ||||
|> Map.from_struct() | ||||
|
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
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?