-
Notifications
You must be signed in to change notification settings - Fork 25.9k
Honor OTLP log document metadata #147799
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
Honor OTLP log document metadata #147799
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c62a61b
Honor OTLP log document metadata
felixbarny 2b2ff28
Update docs/changelog/147799.yaml
felixbarny 98d8013
Delete docs/changelog/147799.yaml
felixbarny 05a5561
Merge branch 'main' into otlp-logs-follow-ups
felixbarny 21aba91
very nit
felixbarny 39341c4
[CI] Auto commit changes from spotless
935495a
Merge branch 'main' into otlp-logs-follow-ups
felixbarny 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
57 changes: 57 additions & 0 deletions
57
...lugin/otel-data/src/main/java/org/elasticsearch/xpack/oteldata/otlp/DocumentMetadata.java
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,57 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| package org.elasticsearch.xpack.oteldata.otlp; | ||
|
|
||
| import io.opentelemetry.proto.common.v1.KeyValue; | ||
|
|
||
| import org.elasticsearch.core.Nullable; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Elastic-specific OTLP attributes that configure per-document indexing metadata. | ||
| */ | ||
| public final class DocumentMetadata { | ||
|
|
||
| public static final String ATTRIBUTE_PREFIX = "elasticsearch"; | ||
| public static final String DOCUMENT_ID_ATTRIBUTE = ATTRIBUTE_PREFIX + ".document_id"; | ||
| public static final String INGEST_PIPELINE_ATTRIBUTE = ATTRIBUTE_PREFIX + ".ingest_pipeline"; | ||
|
|
||
| private DocumentMetadata() {} | ||
|
|
||
| /** | ||
| * Extracts the Elasticsearch document id metadata attribute, if present. | ||
| */ | ||
| public static @Nullable String documentId(List<KeyValue> attributes) { | ||
| return attributeValue(DOCUMENT_ID_ATTRIBUTE, attributes); | ||
| } | ||
|
|
||
| /** | ||
| * Extracts the Elasticsearch ingest pipeline metadata attribute, if present. | ||
| */ | ||
| public static @Nullable String ingestPipeline(List<KeyValue> attributes) { | ||
| return attributeValue(INGEST_PIPELINE_ATTRIBUTE, attributes); | ||
| } | ||
|
|
||
| /** | ||
| * Returns whether an attribute configures per-document indexing metadata. | ||
| */ | ||
| public static boolean isDocumentMetadataAttribute(String attributeKey) { | ||
| return attributeKey.equals(DOCUMENT_ID_ATTRIBUTE) || attributeKey.equals(INGEST_PIPELINE_ATTRIBUTE); | ||
| } | ||
|
|
||
| private static @Nullable String attributeValue(String key, List<KeyValue> attributes) { | ||
| for (int i = 0, size = attributes.size(); i < size; i++) { | ||
| KeyValue attribute = attributes.get(i); | ||
| if (key.equals(attribute.getKey())) { | ||
| return attribute.getValue().getStringValue(); | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
| } | ||
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
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.
I'm not sure there’s much value in putting those functions in a standalone class, since they aren't useful outside the OTLPLogsTransportAction context. I actually prefer local
extractDocumentId.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.
The span doc builder also supports the document_id, which is why I think the shared helper makes sense.