如何在OpenTelemetry java中使用扩展

gfttwv5a  于 12个月前  发布在  Java
关注(0)|答案(1)|浏览(108)

我试图扩展OpenTelemetry java代理,我没有看到任何迹象表明它试图加载我的jar。我正在运行以下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

字符串
我的配置文件是(属性工作):

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


我的分机是:

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) {
    }
    ....


我没有看到任何迹象表明我的扩展已加载,我没有看到任何我的参数上产生的跨度。任何机构可以帮助我吗?

jei2mxaa

jei2mxaa1#

1.配置文件中不支持“otel.javaagent.extensions”。请使用-D添加它。
1.将span处理器添加到实现sdkTracerProviderConfigurer的配置调用中

相关问题