How to use the @azure/core-tracing.getTraceParentHeader function in @azure/core-tracing

To help you get started, we’ve selected a few @azure/core-tracing examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Azure / azure-sdk-for-js / sdk / eventhub / event-hubs / src / diagnostics / instrumentEventData.ts View on Github external
export function instrumentEventData(eventData: EventData, span: Span): EventData {
  if (eventData.properties && eventData.properties[TRACEPARENT_PROPERTY]) {
    return eventData;
  }

  // create a copy so the original isn't modified
  eventData = { ...eventData, properties: { ...eventData.properties } };

  const traceParent = getTraceParentHeader(span.context());
  if (traceParent) {
    eventData.properties![TRACEPARENT_PROPERTY] = traceParent;
  }

  return eventData;
}
github Azure / azure-sdk-for-js / sdk / core / core-http / lib / policies / tracingPolicy.ts View on Github external
const path = URLBuilder.parse(request.url).getPath() || "/";
    const span = tracer.startSpan(path, spanOptions);
    span.setAttributes({
      "http.method": request.method,
      "http.url": request.url,
      requestId: request.requestId
    });

    if (this.userAgent) {
      span.setAttribute("http.user_agent", this.userAgent);
    }

    try {
      // set headers
      const spanContext = span.context();
      const traceParentHeader = getTraceParentHeader(spanContext);
      if (traceParentHeader) {
        request.headers.set("traceparent", traceParentHeader);
        const traceState = spanContext.traceState && spanContext.traceState.serialize();
        // if tracestate is set, traceparent MUST be set, so only set tracestate after traceparent
        if (traceState) {
          request.headers.set("tracestate", traceState);
        }
      }

      const response = await this._nextPolicy.sendRequest(request);
      span.setAttribute("http.status_code", response.status);
      const serviceRequestId = response.headers.get("x-ms-request-id");
      if (serviceRequestId) {
        span.setAttribute("serviceRequestId", serviceRequestId);
      }
      span.end();

@azure/core-tracing

Provides low-level interfaces and helper methods for tracing in Azure SDK

MIT
Latest version published 2 months ago

Package Health Score

84 / 100
Full package analysis