-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Capture messaging header value as span attribute (open-telemetry#6454)
* Capture messaging header value as span attribute * add comment
- Loading branch information
Showing
50 changed files
with
870 additions
and
66 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
.../opentelemetry/instrumentation/api/instrumenter/messaging/CapturedMessageHeadersUtil.java
This file contains 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,38 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.api.instrumenter.messaging; | ||
|
||
import static java.util.Collections.unmodifiableList; | ||
|
||
import io.opentelemetry.api.common.AttributeKey; | ||
import java.util.List; | ||
import java.util.Locale; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.ConcurrentMap; | ||
import java.util.stream.Collectors; | ||
|
||
final class CapturedMessageHeadersUtil { | ||
|
||
private static final ConcurrentMap<String, AttributeKey<List<String>>> attributeKeysCache = | ||
new ConcurrentHashMap<>(); | ||
|
||
static List<String> lowercase(List<String> names) { | ||
return unmodifiableList( | ||
names.stream().map(s -> s.toLowerCase(Locale.ROOT)).collect(Collectors.toList())); | ||
} | ||
|
||
static AttributeKey<List<String>> attributeKey(String headerName) { | ||
return attributeKeysCache.computeIfAbsent(headerName, n -> createKey(n)); | ||
} | ||
|
||
private static AttributeKey<List<String>> createKey(String headerName) { | ||
// headerName is always lowercase, see MessagingAttributesExtractor | ||
String key = "messaging.header." + headerName.replace('-', '_'); | ||
return AttributeKey.stringArrayKey(key); | ||
} | ||
|
||
private CapturedMessageHeadersUtil() {} | ||
} |
This file contains 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
47 changes: 47 additions & 0 deletions
47
...metry/instrumentation/api/instrumenter/messaging/MessagingAttributesExtractorBuilder.java
This file contains 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,47 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.api.instrumenter.messaging; | ||
|
||
import static java.util.Collections.emptyList; | ||
|
||
import java.util.List; | ||
|
||
/** A builder of {@link MessagingAttributesExtractor}. */ | ||
public final class MessagingAttributesExtractorBuilder<REQUEST, RESPONSE> { | ||
|
||
final MessagingAttributesGetter<REQUEST, RESPONSE> getter; | ||
final MessageOperation operation; | ||
List<String> capturedHeaders = emptyList(); | ||
|
||
MessagingAttributesExtractorBuilder( | ||
MessagingAttributesGetter<REQUEST, RESPONSE> getter, MessageOperation operation) { | ||
this.getter = getter; | ||
this.operation = operation; | ||
} | ||
|
||
/** | ||
* Configures the messaging headers that will be captured as span attributes. | ||
* | ||
* <p>The messaging header values will be captured under the {@code messaging.header.<name>} | ||
* attribute key. The {@code <name>} part in the attribute key is the normalized header name: | ||
* lowercase, with dashes replaced by underscores. | ||
* | ||
* @param capturedHeaders A list of messaging header names. | ||
*/ | ||
public MessagingAttributesExtractorBuilder<REQUEST, RESPONSE> setCapturedHeaders( | ||
List<String> capturedHeaders) { | ||
this.capturedHeaders = capturedHeaders; | ||
return this; | ||
} | ||
|
||
/** | ||
* Returns a new {@link MessagingAttributesExtractor} with the settings of this {@link | ||
* MessagingAttributesExtractorBuilder}. | ||
*/ | ||
public MessagingAttributesExtractor<REQUEST, RESPONSE> build() { | ||
return new MessagingAttributesExtractor<>(getter, operation, capturedHeaders); | ||
} | ||
} |
This file contains 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 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 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 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 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 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.