如何在 OpenTelemetry java 中使用扩展

发布于 2025-01-11 09:58:00 字数 2136 浏览 0 评论 0原文

我正在尝试扩展 OpenTelemetry java 代理,但没有看到任何迹象表明它正在尝试加载我的 jar。 我正在运行以下命令:

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

我没有看到任何表明我的扩展已加载的指示,我在生成的跨度上没有看到任何参数。有人可以帮助我吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

葬心 2025-01-18 09:58:00
  1. 配置文件中不支持“otel.javaagent.extensions”。用 -D 添加它。
  2. 将 span 处理器添加到实现 sdkTracerProviderConfigurer 的配置调用中
  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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文