Skip to content
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

feat(protocol): Add OpenTelemetry Context #1617

Merged
merged 6 commits into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
**Features**:

- Dynamic sampling is now based on the volume received by Relay by default and does not include the original volume dropped by client-side sampling in SDKs. This is required for the final dynamic sampling feature in the latest Sentry plans. ([#1591](https://github.com/getsentry/relay/pull/1591))
- Add OpenTelemetry Context ([#1617](https://github.com/getsentry/relay/pull/1617))

**Internal**:

Expand Down
5 changes: 5 additions & 0 deletions relay-general/src/protocol/contexts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ mod runtime;
pub use runtime::*;
mod trace;
pub use trace::*;
mod otel;
pub use otel::*;

use crate::types::{Annotated, FromValue, Object, Value};

Expand Down Expand Up @@ -51,6 +53,8 @@ pub enum Context {
Reprocessing(Box<ReprocessingContext>),
/// Response information.
Response(Box<ResponseContext>),
/// OpenTelemetry information
Otel(Box<OtelContext>),
/// Additional arbitrary fields for forwards compatibility.
#[metastructure(fallback_variant)]
Other(#[metastructure(pii = "true")] Object<Value>),
Expand All @@ -72,6 +76,7 @@ impl Context {
Context::Trace(_) => Some(TraceContext::default_key()),
Context::Monitor(_) => Some(MonitorContext::default_key()),
Context::Response(_) => Some(ResponseContext::default_key()),
Context::Otel(_) => Some(OtelContext::default_key()),
Context::Other(_) => None,
}
}
Expand Down
31 changes: 31 additions & 0 deletions relay-general/src/protocol/contexts/otel.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use crate::types::{Annotated, Object, Value};

/// OpenTelemetry Context
///
/// If an event has this context, it was generated from a OpenTelemetry signal (trace, metric, log).
AbhiPrasad marked this conversation as resolved.
Show resolved Hide resolved
#[derive(Clone, Debug, Default, PartialEq, Empty, FromValue, IntoValue, ProcessValue)]
#[cfg_attr(feature = "jsonschema", derive(JsonSchema))]
pub struct OtelContext {
/// Attributes of the OpenTelemetry span that maps to a Sentry event.
///
/// <https://github.com/open-telemetry/opentelemetry-proto/blob/724e427879e3d2bae2edc0218fff06e37b9eb46e/opentelemetry/proto/trace/v1/trace.proto#L174-L186>
#[metastructure(pii = "maybe", bag_size = "large")]
attributes: Annotated<Object<Value>>,

/// Information about an OpenTelemetry resource.
///
/// <https://github.com/open-telemetry/opentelemetry-proto/blob/724e427879e3d2bae2edc0218fff06e37b9eb46e/opentelemetry/proto/resource/v1/resource.proto>
#[metastructure(pii = "maybe", bag_size = "large")]
resource: Annotated<Object<Value>>,

/// Additional arbitrary fields for forwards compatibility.
#[metastructure(additional_properties, retain = "true", pii = "maybe")]
pub other: Object<Value>,
}

impl OtelContext {
/// The key under which a runtime context is generally stored (in `Contexts`).
pub fn default_key() -> &'static str {
"otel"
}
}
33 changes: 32 additions & 1 deletion relay-general/tests/snapshots/test_fixtures__event_schema.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
source: relay-general/tests/test_fixtures.rs
assertion_line: 109
expression: "relay_general::protocol::event_json_schema()"
---
{
Expand Down Expand Up @@ -825,6 +824,9 @@ expression: "relay_general::protocol::event_json_schema()"
{
"$ref": "#/definitions/ResponseContext"
},
{
"$ref": "#/definitions/OtelContext"
},
{
"type": "object",
"additionalProperties": true
Expand Down Expand Up @@ -2368,6 +2370,35 @@ expression: "relay_general::protocol::event_json_schema()"
}
]
},
"OtelContext": {
"description": " OpenTelemetry Context\n\n If an event has this context, it was generated from a OpenTelemetry signal (trace, metric, log).",
"anyOf": [
{
"type": "object",
"properties": {
"attributes": {
"description": " Attributes of the OpenTelemetry span that maps to a Sentry event.\n\n <https://github.com/open-telemetry/opentelemetry-proto/blob/724e427879e3d2bae2edc0218fff06e37b9eb46e/opentelemetry/proto/trace/v1/trace.proto#L174-L186>",
"default": null,
"type": [
"object",
"null"
],
"additionalProperties": true
},
"resource": {
"description": " Information about an OpenTelemetry resource.\n\n <https://github.com/open-telemetry/opentelemetry-proto/blob/724e427879e3d2bae2edc0218fff06e37b9eb46e/opentelemetry/proto/resource/v1/resource.proto>",
"default": null,
"type": [
"object",
"null"
],
"additionalProperties": true
}
},
"additionalProperties": false
}
]
},
"PosixSignal": {
"description": " POSIX signal with optional extended data.\n\n On Apple systems, signals also carry a code in addition to the signal number describing the\n signal in more detail. On Linux, this code does not exist.",
"anyOf": [
Expand Down