def _translate_to_datadog(self, spans): datadog_spans = [] for span in spans: trace_id, parent_id, span_id = _get_trace_ids(span) # datadog Span is initialized with a reference to the tracer which is # used to record the span when it is finished. We can skip ignore this # because we are not calling the finish method and explictly set the # duration. tracer = None datadog_span = DatadogSpan( tracer, _get_span_name(span), service=self.service, resource=_get_resource(span), span_type=_get_span_type(span), trace_id=trace_id, span_id=span_id, parent_id=parent_id, ) datadog_span.start_ns = span.start_time datadog_span.duration_ns = span.end_time - span.start_time if span.status.canonical_code is not StatusCanonicalCode.OK: datadog_span.error = 1 if span.status.description: exc_type, exc_val = _get_exc_info(span) # no mapping for error.stack since traceback not recorded datadog_span.set_tag("error.msg", exc_val) datadog_span.set_tag("error.type", exc_type) datadog_span.set_tags(span.attributes) # add configured env tag if self.env is not None: datadog_span.set_tag(ENV_KEY, self.env) # add configured application version tag to only root span if self.version is not None and parent_id == 0: datadog_span.set_tag(VERSION_KEY, self.version) # add configured global tags datadog_span.set_tags(self.tags) # add origin to root span origin = _get_origin(span) if origin and parent_id == 0: datadog_span.set_tag(DD_ORIGIN, origin) sampling_rate = _get_sampling_rate(span) if sampling_rate is not None: datadog_span.set_metric(SAMPLE_RATE_METRIC_KEY, sampling_rate) # span events and span links are not supported datadog_spans.append(datadog_span) return datadog_spans
def __init__(self, tracer, context, operation_name): # type: (Tracer, Optional[SpanContext], str) -> None if context is not None: context = SpanContext(ddcontext=context._dd_context, baggage=context.baggage) else: context = SpanContext() super(Span, self).__init__(tracer, context) self.finished = False self._lock = threading.Lock() # use a datadog span self._dd_span = DatadogSpan(tracer._dd_tracer, operation_name, context=context._dd_context)
def _translate_to_datadog(self, spans): datadog_spans = [] for span in spans: trace_id, parent_id, span_id = _get_trace_ids(span) # datadog Span is initialized with a reference to the tracer which is # used to record the span when it is finished. We can skip ignore this # because we are not calling the finish method and explictly set the # duration. tracer = None datadog_span = DatadogSpan( tracer, _get_span_name(span), service=self.service, resource=_get_resource(span), span_type=_get_span_type(span), trace_id=trace_id, span_id=span_id, parent_id=parent_id, ) datadog_span.start_ns = span.start_time datadog_span.duration_ns = span.end_time - span.start_time if span.status.canonical_code is not StatusCanonicalCode.OK: datadog_span.error = 1 if span.status.description: exc_type, exc_val = _get_exc_info(span) # no mapping for error.stack since traceback not recorded datadog_span.set_tag("error.msg", exc_val) datadog_span.set_tag("error.type", exc_type) datadog_span.set_tags(span.attributes) # span events and span links are not supported datadog_spans.append(datadog_span) return datadog_spans
def _translate_to_datadog(self, spans): datadog_spans = [] for span in spans: trace_id, parent_id, span_id = _get_trace_ids(span) # datadog Span is initialized with a reference to the tracer which is # used to record the span when it is finished. We can skip ignore this # because we are not calling the finish method and explictly set the # duration. tracer = None # extract resource attributes to be used as tags as well as potential service name [ resource_tags, resource_service_name, ] = _extract_tags_from_resource(span.resource) datadog_span = DatadogSpan( tracer, _get_span_name(span), service=resource_service_name or self.service, resource=_get_resource(span), span_type=_get_span_type(span), trace_id=trace_id, span_id=span_id, parent_id=parent_id, ) datadog_span.start_ns = span.start_time datadog_span.duration_ns = span.end_time - span.start_time if not span.status.is_ok: datadog_span.error = 1 # loop over events and look for exception events, extract info. # https://github.com/open-telemetry/opentelemetry-python/blob/71e3a7a192c0fc8a7503fac967ada36a74b79e58/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py#L810-L819 if span.events: _extract_tags_from_exception_events( span.events, datadog_span ) # combine resource attributes and span attributes, don't modify existing span attributes combined_span_tags = {} combined_span_tags.update(resource_tags) combined_span_tags.update(span.attributes) datadog_span.set_tags(combined_span_tags) # add configured env tag if self.env is not None: datadog_span.set_tag(ENV_KEY, self.env) # add configured application version tag to only root span if self.version is not None and parent_id == 0: datadog_span.set_tag(VERSION_KEY, self.version) # add configured global tags datadog_span.set_tags(self.tags) # add origin to root span origin = _get_origin(span) if origin and parent_id == 0: datadog_span.set_tag(DD_ORIGIN, origin) sampling_rate = _get_sampling_rate(span) if sampling_rate is not None: datadog_span.set_metric(SAMPLE_RATE_METRIC_KEY, sampling_rate) # span events and span links are not supported except for extracting exception event context datadog_spans.append(datadog_span) return datadog_spans