javajavaagentsopen-telemetry

How to use extensions in OpenTelemetry java


I am trying to extend OpenTelemetry java agent and I don't see any indication it is trying to load my jar. I am running the following cmd:

java -javaagent:../src/main/resources/opentelemetry-javaagent.jar -Dotel.javaagent.configuration-file=../src/main/resources/agent-prp.properties -jar simple-service-1.0-SNAPSHOT-jar-with-dependencies.jar

my config file is (the attributes are working):

otel.javaagent.extensions=/Users/foo/source/simple-service/src/main/resources/span-processor-1.0-SNAPSHOT.jar
otel.resource.attributes=service.name=foooBarr

my extension is:

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.opentelemetry.context.Context;
import io.opentelemetry.sdk.common.CompletableResultCode;
import io.opentelemetry.sdk.trace.ReadWriteSpan;
import io.opentelemetry.sdk.trace.ReadableSpan;
import io.opentelemetry.sdk.trace.SpanProcessor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;

public class FooSpanProcessor implements SpanProcessor {
    private static final ObjectMapper objMapper = new ObjectMapper();
    private static final Logger log = LoggerFactory.getLogger(FooSpanProcessor.class);


    @Override
    public void onStart(Context parentContext, ReadWriteSpan span) {
        log.error("fffffffffff");
        span.setAttribute("fooToken", FooProperties.INSTANCE.fooToken);
        span.setAttribute("service.name", FooProperties.INSTANCE.serviceName);
        span.setAttribute("runtime", FooProperties.INSTANCE.javaVersion);
        span.setAttribute("tracerVersion", "0.0.1");
        span.setAttribute("framework", FooProperties.INSTANCE.frameWork);
        span.setAttribute("envs", FooProperties.INSTANCE.environment);
        span.setAttribute("metaData", FooProperties.INSTANCE.metadata);
    }

    @Override
    public boolean isStartRequired() {
        return true;
    }

    @Override
    public void onEnd(ReadableSpan span) {
    }
    ....

I don't see any indication that my extension is loaded, I don't see any of my parameters on the produced spans. can any body help me?


Solution

    1. "otel.javaagent.extensions" is not supported in the config file. add it with -D.
    2. add the span processor to a config call implementing sdkTracerProviderConfigurer