-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added package attribute extractor (#60)
Co-authored-by: oleksandrh <alex.hrebeniuk@gmail.com>
- Loading branch information
1 parent
ae47739
commit 33ca94e
Showing
4 changed files
with
55 additions
and
4 deletions.
There are no files selected for viewing
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
38 changes: 38 additions & 0 deletions
38
...ain/java/com/digma/otel/javaagent/extension/instrumentation/methods/PackageExtractor.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 @@ | ||
package com.digma.otel.javaagent.extension.instrumentation.methods; | ||
|
||
import com.digma.otel.instrumentation.common.DigmaSemanticAttributes; | ||
import io.opentelemetry.api.common.AttributeKey; | ||
import io.opentelemetry.api.common.AttributesBuilder; | ||
import io.opentelemetry.context.Context; | ||
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor; | ||
import io.opentelemetry.instrumentation.api.instrumenter.code.CodeAttributesGetter; | ||
import io.opentelemetry.instrumentation.api.internal.AttributesExtractorUtil; | ||
|
||
|
||
import javax.annotation.Nullable; | ||
|
||
public final class PackageExtractor<REQUEST, RESPONSE> implements AttributesExtractor<REQUEST, RESPONSE> | ||
{ | ||
private final CodeAttributesGetter<REQUEST> getter; | ||
|
||
private PackageExtractor(CodeAttributesGetter<REQUEST> getter) { | ||
this.getter = getter; | ||
} | ||
|
||
public static <REQUEST, RESPONSE> PackageExtractor<REQUEST, RESPONSE> create(CodeAttributesGetter<REQUEST> getter) { | ||
return new PackageExtractor(getter); | ||
} | ||
|
||
@Override | ||
public void onStart(AttributesBuilder attributes, Context context, REQUEST request) { | ||
Class<?> cls = this.getter.codeClass(request); | ||
if (cls != null) { | ||
AttributesExtractorUtil.internalSet(attributes, AttributeKey.stringKey("digma.instrumentation.extended.package"), cls.getPackage().getName()); | ||
AttributesExtractorUtil.internalSet(attributes, AttributeKey.stringKey("digma.instrumentation.extended.enabled"), "true"); | ||
} | ||
} | ||
|
||
@Override | ||
public void onEnd(AttributesBuilder attributesBuilder, Context context, REQUEST request, @Nullable RESPONSE response, @Nullable Throwable throwable) { | ||
} | ||
} |
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