在Python OpenTelemetry库中配置HTTPS端点。

huangapple go评论87阅读模式
英文:

configure https endpoint in python opentelemetry library

问题

我有以下的代码,试图将opentelemetry跟踪发送到https OTLP端点。然而,它生成了一个证书验证错误。我理解我需要配置一个证书,但不知道如何操作。我已经成功生成了一个证书,但不知道如何在Python库中配置它。

from opentelemetry import trace
# from opentelemetry.exporter.jaeger.thrift import JaegerExporter
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
#from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.resources import SERVICE_NAME, Resource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor

...

resource = Resource(attributes={
        SERVICE_NAME: "demo"
    })
provider = TracerProvider(resource=resource)
processor = BatchSpanProcessor(OTLPSpanExporter(endpoint="<endpointhost>/v1/traces", insecure=True))
provider.add_span_processor(processor)
trace.set_tracer_provider(provider)

感谢任何帮助。

英文:

i
I have the following code that tries to send opentelemetry traces to an https OTLP endpoint. However, it generates a certificate verification error. I understand that I need to configure a certificate but don't know how. I have succeeded to generate a certificate, but don't know how to configure it in the python library.

from opentelemetry import trace
# from opentelemetry.exporter.jaeger.thrift import JaegerExporter
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
#from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.resources import SERVICE_NAME, Resource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor

...

resource = Resource(attributes={
        SERVICE_NAME: &quot;demo&quot;
    })
    provider = TracerProvider(resource=resource)
    processor = BatchSpanProcessor(OTLPSpanExporter(endpoint=&quot;&lt;endpointhost&gt;/v1/traces&quot;, insecure=True))
    provider.add_span_processor(processor)
    trace.set_tracer_provider(provider)

thanks for any help

答案1

得分: 1

我认为,通过像下面这样提供一个证书文件,我成功解决了这个问题

processor = BatchSpanProcessor(OTLPSpanExporter(endpoint="<ENDPOINTHOST>/v1/traces", certificate_file='证书文件'))
英文:

I think, I managed to resolve the problem by providing a certificate file like below

    processor = BatchSpanProcessor(OTLPSpanExporter(endpoint=&quot;&lt;ENDPOINTHOST&gt;/v1/traces&quot;, certificate_file=&#39;CERTIFICATE FILE&#39;))

huangapple
  • 本文由 发表于 2023年7月20日 21:26:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/76730388.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定