-
-
Notifications
You must be signed in to change notification settings - Fork 525
Unify Logs and Metrics implementations #2826
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0f6d57a
Unify Logs and Metrics implementations
sl0thentr0py 580896e
Reduce hash allocations
sl0thentr0py 8f6e1a5
Update sentry-ruby/lib/sentry/log_event.rb
sl0thentr0py 8f385ee
Fix transform_values
sl0thentr0py 94da548
Optimize scope attribute setting
sl0thentr0py 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
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 |
|---|---|---|
|
|
@@ -46,7 +46,7 @@ def clear | |
| # @param hint [Hash] the hint data that'll be passed to event processors. | ||
| # @return [Event] | ||
| def apply_to_event(event, hint = nil) | ||
| unless event.is_a?(CheckInEvent) || event.is_a?(LogEvent) | ||
| unless event.is_a?(CheckInEvent) | ||
| event.tags = tags.merge(event.tags) | ||
| event.user = user.merge(event.user) | ||
| event.extra = extra.merge(event.extra) | ||
|
|
@@ -60,10 +60,6 @@ def apply_to_event(event, hint = nil) | |
| event.attachments = attachments | ||
| end | ||
|
|
||
| if event.is_a?(LogEvent) | ||
| event.user = user.merge(event.user) | ||
| end | ||
|
|
||
| if span | ||
| event.contexts[:trace] ||= span.get_trace_context | ||
|
|
||
|
|
@@ -92,18 +88,31 @@ def apply_to_event(event, hint = nil) | |
| # A leaner version of apply_to_event that applies to | ||
| # lightweight payloads like Logs and Metrics. | ||
| # | ||
| # Only adds trace_id, span_id and user from the scope. | ||
| # Adds trace_id, span_id, user from the scope and default attributes from configuration. | ||
sl0thentr0py marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # | ||
| # @param telemetry [MetricEvent] | ||
| # @return [MetricEvent] | ||
| # @param telemetry [MetricEvent, LogEvent] the telemetry event to apply scope context to | ||
| # @return [MetricEvent, LogEvent] the telemetry event with scope context applied | ||
| def apply_to_telemetry(telemetry) | ||
| # TODO-neel when new scope set_attribute api is added: add them here | ||
| telemetry.user = user.merge(telemetry.user) | ||
|
|
||
| trace_context = span ? span.get_trace_context : propagation_context.get_trace_context | ||
| telemetry.trace_id = trace_context[:trace_id] | ||
| telemetry.span_id = trace_context[:span_id] | ||
|
|
||
| configuration = Sentry.configuration | ||
| return telemetry unless configuration | ||
|
|
||
| telemetry.attributes["sentry.sdk.name"] ||= Sentry.sdk_meta["name"] | ||
| telemetry.attributes["sentry.sdk.version"] ||= Sentry.sdk_meta["version"] | ||
| telemetry.attributes["sentry.environment"] ||= configuration.environment if configuration.environment | ||
| telemetry.attributes["sentry.release"] ||= configuration.release if configuration.release | ||
| telemetry.attributes["server.address"] ||= configuration.server_name if configuration.server_name | ||
|
|
||
| if configuration.send_default_pii && !user.empty? | ||
| telemetry.attributes["user.id"] ||= user[:id] if user[:id] | ||
| telemetry.attributes["user.name"] ||= user[:username] if user[:username] | ||
| telemetry.attributes["user.email"] ||= user[:email] if user[:email] | ||
| end | ||
|
Collaborator
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. @sl0thentr0py would be good to optimize this to avoid extra hash allocations, otherwise this will be a performance regression. |
||
|
|
||
| telemetry | ||
| end | ||
|
|
||
|
|
||
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,30 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require "json" | ||
|
|
||
| module Sentry | ||
| module Utils | ||
| module TelemetryAttributes | ||
| private | ||
|
|
||
| def attribute_hash(value) | ||
| case value | ||
| when String | ||
| { value: value, type: "string" } | ||
| when TrueClass, FalseClass | ||
| { value: value, type: "boolean" } | ||
| when Integer | ||
| { value: value, type: "integer" } | ||
| when Float | ||
| { value: value, type: "double" } | ||
| else | ||
| begin | ||
| { value: JSON.generate(value), type: "string" } | ||
| rescue | ||
| { value: value, type: "string" } | ||
| end | ||
| end | ||
| end | ||
| 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.
this is now just
span_idtop level field