OTelCollector

class duetector.collectors.otel.OTelInitiator(*args, **kwargs)[source]

Bases: object

Host the OpenTelemetry SDK and initialize the provider and exporter.

Avaliable exporters:
  • console

  • otlp-grpc

  • otlp-http

  • jaeger-thrift

  • jaeger-grpc

  • zipkin-http

  • zipkin-json

  • prometheus

Example:

otel = OTelInitiator()
trace = otel.initialize(
    service_name="duetector",
    exporter="console",
)

from opentelemetry import trace
tracer = trace.get_tracer(__name__)
with tracer.start_as_current_span("test") as span:
    span.set_attribute("test", "test")

otel.shutdown()
exporter_cls = {'console': <class 'opentelemetry.sdk.trace.export.ConsoleSpanExporter'>, 'jaeger-grpc': <class 'opentelemetry.exporter.jaeger.proto.grpc.JaegerExporter'>, 'jaeger-thrift': <class 'opentelemetry.exporter.jaeger.thrift.JaegerExporter'>, 'otlp-grpc': <class 'opentelemetry.exporter.otlp.proto.grpc.trace_exporter.OTLPSpanExporter'>, 'otlp-http': <class 'opentelemetry.exporter.otlp.proto.http.trace_exporter.OTLPSpanExporter'>, 'zipkin-http': <class 'opentelemetry.exporter.zipkin.proto.http.ZipkinExporter'>, 'zipkin-json': <class 'opentelemetry.exporter.zipkin.json.ZipkinExporter'>}
initialize(service_name='unknown-service', resource_kwargs: dict[str, Any] | None = None, provider_kwargs: dict[str, Any] | None = None, exporter='console', exporter_kwargs: dict[str, Any] | None = None, processor_kwargs: dict[str, Any] | None = None) None[source]
shutdown()[source]
class duetector.collectors.otel.OTelCollector(config: dict[str, Any] | None = None, *args, **kwargs)[source]

Bases: Collector, OTelInspector

A collector using OpenTelemetry SDK.

Config:
  • exporter: One of console, otlp-grpc, otlp-http, jaeger-thrift, jaeger-grpc, zipkin-http, zipkin-json, see OTelInitiator for more details

  • exporter_kwargs: A dict of kwargs for exporter

Note

Since v1.35, the Jaeger supports OTLP natively. Please use the OTLP exporter instead. Support for this exporter will end July 2023.

_emit(t: Tracking)[source]

Emit a tracking to collector, should be implemented by subclasses

default_config = {'backend_args': {'max_workers': 10}, 'disabled': True, 'exporter': 'console', 'exporter_kwargs': {}, 'grpc_exporter_kwargs': {'certificate_chain_path': '', 'private_key_path': '', 'root_certificates_path': '', 'secure': False}, 'processor_kwargs': {}, 'statis_id': ''}

Default config for Collector

property endpoint: str | None
property exporter: str
property exporter_kwargs: dict[str, Any]
property grpc_exporter_kwargs: dict[str, Any]
property processor_kwargs: dict[str, Any]
property service_name: str
service_prefix = 'duetector'
service_sep = '-'
shutdown()[source]

Shutdown backend executor

summary() dict[source]

Get summary of current collector, should be implemented by subclasses