Skip to content

Support trace groups in standard otel proto codec#5539

Merged
kkondaka merged 4 commits intoopensearch-project:mainfrom
kkondaka:otel-trace-groups
Apr 7, 2025
Merged

Support trace groups in standard otel proto codec#5539
kkondaka merged 4 commits intoopensearch-project:mainfrom
kkondaka:otel-trace-groups

Conversation

@kkondaka
Copy link
Copy Markdown
Collaborator

Description

  1. Support OTEL trace groups and trace group fields in standaed OTEL proto codec
  2. Cleanup and address comments from Add support for generating Standard(OTEL) conformant events in DataPrepper #5524
  3. Add template mappings for using standard OTEL log/trace/metrics in opensearch sink

Issues Resolved

Resolves #5259

Check List

  • [X ] New functionality includes testing.
  • New functionality has a documentation issue. Please link to it in this PR.
    • New functionality has javadoc added
  • [X ] Commits are signed with a real name per the DCO

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@kkondaka
Copy link
Copy Markdown
Collaborator Author

@KarstenSchnitter @dlvenable please review

Copy link
Copy Markdown
Collaborator

@KarstenSchnitter KarstenSchnitter left a comment

Choose a reason for hiding this comment

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

Thanks for providing this change.

I managed to review the logs and metrics template. Some of the comments on logs translate to metrics as well. I will review more of this PR over the weekend.

Comment on lines +19 to +25
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 128
}
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I do not think, that it is necessary to do this kind of pattern on almost all of the OTel fields. They are usually very short to save space. instrumentationScope.name usually takes the form of a url, e.g. io.opentelemetry.runtime-telemetry-java8. I recommend using only the keyword field type. 128 characters also seems to be more than enough. Is there a particular reason to go for text as well?

"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is a semantic version number. 256 seams way to long IMHO.

"path": "observedTimestamp"
},
"traceId": {
"ignore_above": 256,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This will always be 32 characters of a hex encoded 16 byte array.

"type": "keyword"
},
"spanId": {
"ignore_above": 256,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This will always be 16 characters of a hex encoded 8 byte array.

"type": "keyword"
},
"flags": {
"type": "integer"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is a bit mask. I am not sure, whether there are better field types available.

},
"kind": {
"type": "keyword",
"ignore_above": 128
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is actually an enum with well-known values. The longest is EXPONENTIAL_HISTOGRAM.

"type": "date"
},
"@timestamp": {
"type": "date"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why is this not date_nanos?

"type": "double"
},
"max": {
"type": "float"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why not use double?

Copy link
Copy Markdown
Collaborator

@KarstenSchnitter KarstenSchnitter left a comment

Choose a reason for hiding this comment

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

I reviewed everything I left out in my last review. I haved worked quite a lot with mapping templates for OTel data. I can only recommend to use component templates to ease the definition. Resource attributes and Instrumentation Scope handling can be shared amongst the signals. It needs to be the same for efficient analysis anyways. We also should give users the option to extend the templates for covering semantic conventions on the attributes, e..g., specifying http.status.code to be an integer. I added a lot of coments on the mappings, which also apply to the other signals and sometimes other fields.

Comment on lines +8 to +74
"resource_attributes_map": {
"mapping": {
"type": "keyword"
},
"path_match": "resource.attributes.*"
}
},
{
"span_attributes_map": {
"mapping": {
"type": "keyword"
},
"path_match": "span.attributes.*"
}
}
],
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why do you porpose dynamic templates for span and resource attributes but not instrumentation scope? For logs and metrics there was a mapping to object. I like ethe dynamic templating better. But this should be uniform for all three signals and all three attribute collections.

}
},
"kind": {
"ignore_above": 128,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is actually an enum with known values. The longest is SPAN_KIND_UNSPECIFIED.

Comment on lines +78 to +80
"attributes": {
"type": "object"
},
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is semantically the same as the span attributes from the dynamic templates.

Comment on lines +240 to +275
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Just using a keyword should be sufficient. There are two schemaUrls though: One for resource attributes and one for instrumenation scope attributes. Logs and metrics are missing this entry entirely.

"ignore_above": 1024,
"type": "keyword"
},
"traceGroupFields": {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It would actually be nice to add (resource) attributes to the trace group in a future extension.

},
"flags": 0,
"severityNumber": 2,
"serviceName": "testServiceName",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This should have stayed.

"kind": "GAUGE",
"flags": 0,
"description": "testGaugeDescription",
"serviceName": null,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

THis should have stayed, but not using null which is somewhat invalid. All OTel resources SHOULD have a service name.

@kkondaka
Copy link
Copy Markdown
Collaborator Author

@KarstenSchnitter thank you very much for the detailed review. Since you have experience, would it be possible to provide me the complete template files?

@KarstenSchnitter
Copy link
Copy Markdown
Collaborator

@KarstenSchnitter thank you very much for the detailed review. Since you have experience, would it be possible to provide me the complete template files?

Yes, I am going to work on it today.

@KarstenSchnitter
Copy link
Copy Markdown
Collaborator

@kkondaka please find my proposal in kkondaka#2.

Comment on lines +55 to +73
{
"double_attributes": {
"mapping": {
"type": "double"
},
"path_match": "attributes.*",
"match_mapping_type": "double"
}
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can you add at least string attributs, if the default was not working? And similar for the other attributes.

Suggested change
{
"double_attributes": {
"mapping": {
"type": "double"
},
"path_match": "attributes.*",
"match_mapping_type": "double"
}
}
{
"double_attributes": {
"mapping": {
"type": "double"
},
"path_match": "attributes.*",
"match_mapping_type": "double"
}
},
{
"string_attributes": {
"mapping": {
"type": "keyword",
"ignore_above": 256
},
"path_match": "attributes.*",
"match_mapping_type": "string"
}
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@KarstenSchnitter I have the change and verified that it works great. Please take a look at the diffs. Let's plan to make any other suggestions you may have in another PR

Copy link
Copy Markdown
Collaborator

@KarstenSchnitter KarstenSchnitter Apr 7, 2025

Choose a reason for hiding this comment

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

@kkondaka: Great, that it works. Can you add the string attributes for resource and instrumentation scope attributes as well? Then we should be good to go.

kkondaka added 3 commits April 7, 2025 04:20
Signed-off-by: Krishna Kondaka <krishkdk@amazon.com>
…gs/traces/metrics

Signed-off-by: Krishna Kondaka <krishkdk@amazon.com>
Signed-off-by: Krishna Kondaka <krishkdk@amazon.com>
@kkondaka kkondaka force-pushed the otel-trace-groups branch from ecdd704 to 076047f Compare April 7, 2025 04:20
Signed-off-by: Krishna Kondaka <krishkdk@amazon.com>
Copy link
Copy Markdown
Collaborator

@KarstenSchnitter KarstenSchnitter left a comment

Choose a reason for hiding this comment

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

The changed (non-standard) metrics template is now missing the string attributes. Please add them. Otherwise, this looks good.

"path_match": "resource.attributes.*",
"match_mapping_type": "double"
}
},
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This one is now missing the string attributes for resources, scope and plain.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Thanks @KarstenSchnitter. Will do a separate PR for this.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

These are existing mappings. Not focusing on these in this PR, anyways.

for (final Span span : spans) {
assertThat(span.getTraceGroup(), nullValue());
assertThat(span.getTraceGroupFields(), nullValue());
if (span.getParentSpanId().isEmpty()) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is a somewhat loose assertion. Do we even know if we ever get non-empty spans?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This is the exact same code that exists in OTelProtoOpensearchCodecTest. I did not include previously because there was not tracegroups support previously.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yea, I see that you have expanded the scope of this test.

Could it be split into two different tests? One for each scenario?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@dlvenable The test data is coming from resources/test-request.json and it has two spans with parentSpan and one without parentSpan. So, I think this test is fine.

private static final String DROPPED_LINKS_COUNT_KEY = "droppedLinksCount";
private static final String SERVICE_NAME_KEY = "serviceName";
private static final String TRACE_GROUP_KEY = "traceGroup";
public static final String SERVICE_NAME_KEY = "serviceName";
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If you are using these in the tests, make them package protected. Remove public.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It needs to be public because it is used in data-prepper-plugins/otel-proto-common/src/main/java/org/opensearch/dataprepper/plugins/otel/codec/OTelProtoStandardCodec.java


public enum IndexType {
TRACE_ANALYTICS_RAW("trace-analytics-raw"),
TRACE_ANALYTICS_RAW_STANDARD("trace-analytics-standard-raw"),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The term standard is unclear. Can you give a more precise adjective? Perhaps otel?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We can resolve in a follow-on PR.

@kkondaka kkondaka merged commit 6be0b97 into opensearch-project:main Apr 7, 2025
63 of 68 checks passed
amdhing pushed a commit to amdhing/data-prepper that referenced this pull request Apr 16, 2025
…#5539)

* Support trace groups in standard otel proto codec

Signed-off-by: Krishna Kondaka <krishkdk@amazon.com>

* Addressed review comments. Verified the functionality for standard logs/traces/metrics

Signed-off-by: Krishna Kondaka <krishkdk@amazon.com>

* Addressed review comments

Signed-off-by: Krishna Kondaka <krishkdk@amazon.com>

* Added string mappings for resource and scope

Signed-off-by: Krishna Kondaka <krishkdk@amazon.com>

---------

Signed-off-by: Krishna Kondaka <krishkdk@amazon.com>
Davidding4718 pushed a commit to Davidding4718/data-prepper that referenced this pull request Apr 25, 2025
…#5539)

* Support trace groups in standard otel proto codec

Signed-off-by: Krishna Kondaka <krishkdk@amazon.com>

* Addressed review comments. Verified the functionality for standard logs/traces/metrics

Signed-off-by: Krishna Kondaka <krishkdk@amazon.com>

* Addressed review comments

Signed-off-by: Krishna Kondaka <krishkdk@amazon.com>

* Added string mappings for resource and scope

Signed-off-by: Krishna Kondaka <krishkdk@amazon.com>

---------

Signed-off-by: Krishna Kondaka <krishkdk@amazon.com>
Davidding4718 pushed a commit to Davidding4718/data-prepper that referenced this pull request Apr 25, 2025
…#5539)

* Support trace groups in standard otel proto codec

Signed-off-by: Krishna Kondaka <krishkdk@amazon.com>

* Addressed review comments. Verified the functionality for standard logs/traces/metrics

Signed-off-by: Krishna Kondaka <krishkdk@amazon.com>

* Addressed review comments

Signed-off-by: Krishna Kondaka <krishkdk@amazon.com>

* Added string mappings for resource and scope

Signed-off-by: Krishna Kondaka <krishkdk@amazon.com>

---------

Signed-off-by: Krishna Kondaka <krishkdk@amazon.com>
Mamol27 pushed a commit to Mamol27/data-prepper that referenced this pull request May 6, 2025
…#5539)

* Support trace groups in standard otel proto codec

Signed-off-by: Krishna Kondaka <krishkdk@amazon.com>

* Addressed review comments. Verified the functionality for standard logs/traces/metrics

Signed-off-by: Krishna Kondaka <krishkdk@amazon.com>

* Addressed review comments

Signed-off-by: Krishna Kondaka <krishkdk@amazon.com>

* Added string mappings for resource and scope

Signed-off-by: Krishna Kondaka <krishkdk@amazon.com>

---------

Signed-off-by: Krishna Kondaka <krishkdk@amazon.com>
Signed-off-by: mamol27 <mamol27@yandex.ru>
@kkondaka kkondaka deleted the otel-trace-groups branch July 1, 2025 17:04
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.

OTEL sources should create events without any transformations

3 participants