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(spans): Reintroduce OTLP endpoint #4223

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

jjbayer
Copy link
Member

@jjbayer jjbayer commented Nov 5, 2024

Restore the OTLP endpoint that was removed in #3973.

This PR moves the parsing of the trace data to the processor to ensure fast response times.

I also renamed the endpoint from /spans/ to /otlp/v1/traces/ to be consistent with https://opentelemetry.io/docs/languages/sdk-configuration/otlp-exporter/#otel_exporter_otlp_endpoint.

fixes: https://github.com/getsentry/team-ingest/issues/569

@jjbayer jjbayer marked this pull request as ready for review November 6, 2024 09:21
@jjbayer jjbayer requested a review from a team as a code owner November 6, 2024 09:21
@@ -74,6 +75,7 @@ pub fn routes(config: &Config) -> Router<ServiceState>{
.route("/api/:project_id/minidump/", minidump::route(config))
.route("/api/:project_id/events/:event_id/attachments/", post(attachments::handle))
.route("/api/:project_id/unreal/:sentry_key/", unreal::route(config))
.route("/api/:project_id/traces-data/", traces_data::route(config))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it currently "traces-data"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the previous impl it was /spans/ i wanted to name it after the data type it accepts (TracesData) to be consistent with /minidump/, /csp-report/, etc. But reading the link above a bit more, we should maybe even name it /otel/v1/traces/ to be future proof.

For OTLP/HTTP, exporters in the SDK construct signal-specific URLs when this environment variable is set. This means that if you’re sending traces, metrics, and logs, the following URLs are constructed from the example above:

Traces: "http://my-api-endpoint/v1/traces"
Metrics: "http://my-api-endpoint/v1/metrics"
Logs: "http://my-api-endpoint/v1/logs"

https://opentelemetry.io/docs/languages/sdk-configuration/otlp-exporter/#otel_exporter_otlp_endpoint

@@ -74,6 +75,7 @@ pub fn routes(config: &Config) -> Router<ServiceState>{
.route("/api/:project_id/minidump/", minidump::route(config))
.route("/api/:project_id/events/:event_id/attachments/", post(attachments::handle))
.route("/api/:project_id/unreal/:sentry_key/", unreal::route(config))
.route("/api/:project_id/traces-data/", traces_data::route(config))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it currently "traces-data"?

relay-server/src/envelope.rs Show resolved Hide resolved
@@ -16,16 +22,73 @@ pub use processing::*;

pub fn filter(state: &mut ProcessEnvelopeState<SpanGroup>) {
let disabled = state.should_filter(Feature::StandaloneSpanIngestion);
let otel_disabled = state.should_filter(Feature::OtelEndpoint);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also check this in the fast path (aka check_envelope).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do, via

// Check feature.
if let Some(disabled_feature) = envelope
.required_features()
.iter()
.find(|f| !self.has_feature(**f))
{
return Err(DiscardReason::FeatureDisabled(*disabled_feature));
}

Not sure if that check should use should_filter instead of has_feature.

Comment on lines +62 to +68
let Ok(payload) = serde_json::to_vec(&span) else {
track_invalid(managed_envelope, DiscardReason::Internal);
continue;
};
let mut item = Item::new(ItemType::OtelSpan);
item.set_payload(ContentType::Json, payload);
managed_envelope.envelope_mut().add_item(item);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really unfortunate, but I can't think of anything better either ...

This brings up the question, is the OtelSpan item always Json, or also allowed to be protobuf?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean the fact that we parse OTLP, serialize it as JSON, and then parse and convert it into our own span format again?

It's definitely suboptimal, but I prefer this over having different code paths for both.

This brings up the question, is the OtelSpan item always Json, or also allowed to be protobuf?

Currently it has to be JSON:

let mut annotated_span = match item.ty() {
ItemType::OtelSpan => match serde_json::from_slice::<OtelSpan>(&item.payload()) {

Comment on lines 82 to 87
Some(&ContentType::Json) => {
serde_json::from_slice(&item.payload()).map_err(|_| DiscardReason::InvalidJson)
}
Some(&ContentType::Protobuf) => {
TracesData::decode(item.payload()).map_err(|_| DiscardReason::InvalidProtobuf)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should log the errors here in debug, makes debugging issues much much easier.

@jjbayer jjbayer marked this pull request as draft November 7, 2024 15:25
@jjbayer
Copy link
Member Author

jjbayer commented Nov 7, 2024

Converting back to draft, unclear if needed.

@jjbayer jjbayer removed their assignment Nov 8, 2024
@jjbayer jjbayer closed this Nov 12, 2024
@jjbayer jjbayer reopened this Nov 15, 2024
@jjbayer jjbayer self-assigned this Nov 15, 2024
@jjbayer jjbayer marked this pull request as ready for review November 15, 2024 10:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants