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: rename batches property of Trace to ResourceSpans to be OTEL compatible #3895

Merged
merged 10 commits into from
Jul 25, 2024

Conversation

javiermolinar
Copy link
Contributor

@javiermolinar javiermolinar commented Jul 22, 2024

What this PR does:
Currently, the response from /api/traces/ when the the header application/json is set is not OTEL compatible.
The goal of this PR is to prepare the ground for a V2 traces API by making the response OTEL compatible without breaking the current behavior.

I have explored two approaches. The first one was creating a new TraceV2 proto message type. But that introduced a cascade of changes ending with cluttered code, adding even more complexity to the code base. With this approach, we keep the code as it is while being more descriptive by replacing the generic Batches with a more specific ResourceSpans.

To make it retro-compatible, the response when the content-type header is application/json remains the same:

jsonStr = strings.Replace(jsonStr, `"resourceSpans":`, `"batches":`, 1)

Which issue(s) this PR fixes:
Fixes #3802
Checklist

  • [X ] Tests updated
  • Documentation added
  • [ X] CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

@javiermolinar javiermolinar changed the title rename batches property of Trace to ResourceSpans to be OTEL compatible feat: rename batches property of Trace to ResourceSpans to be OTEL compatible Jul 23, 2024
@javiermolinar javiermolinar marked this pull request as draft July 24, 2024 13:35
@javiermolinar javiermolinar marked this pull request as ready for review July 25, 2024 08:36
)

// Marshal a Trace to an OTEL compatible JSON replacing resourceSpans by batches
func MarshalToJSONV1(t *Trace) ([]byte, error) {
Copy link
Member

Choose a reason for hiding this comment

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

it would be nice to get a short comment about why this method exists. how we renamed the batches field to resourceSpans and these utility methods are for (un)marshaling json from the v1 traces endpoint to the current proto object

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I can add more info

@@ -18,3 +18,4 @@
/tempodb/encoding/benchmark_block
private-key.key
integration/e2e/e2e_integration_test[0-9]*
.tempo.yaml
Copy link
Member

Choose a reason for hiding this comment

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

what's this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is my local config to debug Tempo. I can leave it out

Copy link
Member

Choose a reason for hiding this comment

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

it's fine. just interested

@joe-elliott joe-elliott merged commit 5cae77c into grafana:main Jul 25, 2024
14 checks passed
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.

Trace by ID: JSON response does not align with OTLP JSON format
2 participants