How to use the @opentelemetry/types.TraceFlags.SAMPLED function in @opentelemetry/types

To help you get started, we’ve selected a few @opentelemetry/types 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 open-telemetry / opentelemetry-js / packages / opentelemetry-tracing / src / BasicTracer.ts View on Github external
const parentContext = this._getParentSpanContext(options.parent);
    // make sampling decision
    const samplingDecision = this._sampler.shouldSample(parentContext);
    const spanId = randomSpanId();
    let traceId;
    let traceState;
    if (!parentContext || !isValid(parentContext)) {
      // New root span.
      traceId = randomTraceId();
    } else {
      // New child span.
      traceId = parentContext.traceId;
      traceState = parentContext.traceState;
    }
    const traceFlags = samplingDecision
      ? TraceFlags.SAMPLED
      : TraceFlags.UNSAMPLED;
    const spanContext = { traceId, spanId, traceFlags, traceState };
    const recordEvents = options.isRecording || false;
    if (!recordEvents && !samplingDecision) {
      this.logger.debug('Sampling is off, starting no recording span');
      return new NoRecordingSpan(spanContext);
    }

    const span = new Span(
      this,
      name,
      spanContext,
      options.kind || types.SpanKind.INTERNAL,
      parentContext ? parentContext.spanId : undefined,
      options.links || [],
      options.startTime
github open-telemetry / opentelemetry-js / packages / opentelemetry-tracing / src / export / SimpleSpanProcessor.ts View on Github external
onEnd(span: Span): void {
    if (span.context().traceFlags !== TraceFlags.SAMPLED) return;
    this._exporter.export([span.toReadableSpan()], () => {});
  }
github open-telemetry / opentelemetry-js / packages / opentelemetry-tracing / src / export / BatchSpanProcessor.ts View on Github external
onEnd(span: Span): void {
    if (span.context().traceFlags !== TraceFlags.SAMPLED) return;
    this._addToBuffer(span.toReadableSpan());
  }