How to use the @opentelemetry/types.CanonicalCode.OK 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-exporter-jaeger / src / transform.ts View on Github external
const traceIdLow = span.spanContext.traceId.slice(16);
  const parentSpan = span.parentSpanId
    ? Utils.encodeInt64(span.parentSpanId)
    : ThriftUtils.emptyBuffer;

  const tags = Object.keys(span.attributes).map(
    (name): Tag => ({ key: name, value: toTagValue(span.attributes[name]) })
  );
  tags.push({ key: 'status.code', value: span.status.code });
  tags.push({ key: 'status.name', value: CanonicalCode[span.status.code] });
  if (span.status.message) {
    tags.push({ key: 'status.message', value: span.status.message });
  }
  // Ensure that if Status.Code is not OK, that we set the "error" tag on the
  // Jaeger span.
  if (span.status.code !== CanonicalCode.OK) {
    tags.push({ key: 'error', value: true });
  }

  if (span.kind !== undefined) {
    tags.push({ key: 'span.kind', value: SpanKind[span.kind] });
  }

  const spanTags: ThriftTag[] = ThriftUtils.getThriftTags(tags);

  const logs = span.events.map(
    (event): Log => {
      const fields: Tag[] = [{ key: 'message.id', value: event.name }];
      const attrs = event.attributes;
      if (attrs) {
        Object.keys(attrs).forEach(attr =>
          fields.push({ key: attr, value: toTagValue(attrs[attr]) })
github open-telemetry / opentelemetry-js / packages / opentelemetry-plugin-redis / src / utils.ts View on Github external
const endSpan = (span: Span, err?: Error | null) => {
  if (err) {
    span.setStatus({
      code: CanonicalCode.UNKNOWN,
      message: err.message,
    });
  } else {
    span.setStatus({ code: CanonicalCode.OK });
  }
  span.end();
};
github open-telemetry / opentelemetry-js / packages / opentelemetry-plugin-mongodb-core / src / mongodb.ts View on Github external
return function patchedEnd(this: {}, ...args: unknown[]) {
      const error = args[0];
      if (error instanceof Error) {
        span.setStatus({
          code: CanonicalCode.UNKNOWN,
          message: error.message,
        });
      } else {
        span.setStatus({
          code: CanonicalCode.OK,
        });
      }
      span.end();
      return resultHandler.apply(this, args);
    };
  }
github Azure / azure-sdk-for-js / sdk / eventhub / event-hubs / src / sender.ts View on Github external
eventData[i] = instrumentEventData(eventData[i], messageSpan);
          messageSpan.end();
        }
      }
    } else if (isEventDataBatch(eventData)) {
      spanContextsToLink = eventData._messageSpanContexts;
    }

    const sendSpan = this._createSendSpan(getParentSpan(options), spanContextsToLink);

    try {
      const result = await this._eventHubSender!.send(eventData, {
        ...this._senderOptions,
        ...options
      });
      sendSpan.setStatus({ code: CanonicalCode.OK });
      return result;
    } catch (err) {
      sendSpan.setStatus({
        code: CanonicalCode.UNKNOWN,
        message: err.message
      });
      throw err;
    } finally {
      sendSpan.end();
    }
  }
github open-telemetry / opentelemetry-js / packages / opentelemetry-plugin-http / src / utils.ts View on Github external
export const parseResponseStatus = (
  statusCode: number
): Omit => {
  if (statusCode < 200 || statusCode > 504) {
    return { code: CanonicalCode.UNKNOWN };
  } else if (statusCode >= 200 && statusCode < 400) {
    return { code: CanonicalCode.OK };
  } else {
    switch (statusCode) {
      case 400:
        return { code: CanonicalCode.INVALID_ARGUMENT };
      case 504:
        return { code: CanonicalCode.DEADLINE_EXCEEDED };
      case 404:
        return { code: CanonicalCode.NOT_FOUND };
      case 403:
        return { code: CanonicalCode.PERMISSION_DENIED };
      case 401:
        return { code: CanonicalCode.UNAUTHENTICATED };
      case 429:
        return { code: CanonicalCode.RESOURCE_EXHAUSTED };
      case 501:
        return { code: CanonicalCode.UNIMPLEMENTED };
github Azure / azure-sdk-for-js / sdk / eventhub / event-hubs / src / partitionPump.ts View on Github external
export async function trace(fn: () => Promise, span: Span): Promise {
  try {
    await fn();
    span.setStatus({ code: CanonicalCode.OK });
  } catch (err) {
    span.setStatus({
      code: CanonicalCode.UNKNOWN,
      message: err.message
    });
    throw err;
  } finally {
    span.end();
  }
}
github open-telemetry / opentelemetry-js / packages / opentelemetry-plugin-postgres / opentelemetry-plugin-pg / src / pg.ts View on Github external
return new Promise((resolve, _) => {
                span.setStatus({ code: CanonicalCode.OK });
                span.end();
                resolve(result);
              });
            })
github open-telemetry / opentelemetry-js / packages / opentelemetry-plugin-grpc / src / grpc.ts View on Github external
const wrappedFn = (err: grpcTypes.ServiceError, res: any) => {
        if (err) {
          if (err.code) {
            span.setStatus(_grpcStatusCodeToSpanStatus(err.code));
            span.setAttribute(
              AttributeNames.GRPC_STATUS_CODE,
              err.code.toString()
            );
          }
          span.setAttributes({
            [AttributeNames.GRPC_ERROR_NAME]: err.name,
            [AttributeNames.GRPC_ERROR_MESSAGE]: err.message,
          });
        } else {
          span.setStatus({ code: CanonicalCode.OK });
          span.setAttribute(
            AttributeNames.GRPC_STATUS_CODE,
            plugin._moduleExports.status.OK.toString()
          );
        }

        span.end();
        callback(err, res);
      };
      return plugin._tracer.bind(wrappedFn);
github open-telemetry / opentelemetry-js / packages / opentelemetry-plugin-postgres / opentelemetry-plugin-pg / src / utils.ts View on Github external
return function patchedCallback(
    this: pgTypes.Client & PgClientExtended,
    err: Error,
    res: object
  ) {
    if (err) {
      span.setStatus({
        code: CanonicalCode.UNKNOWN,
        message: err.message,
      });
    } else if (res) {
      span.setStatus({ code: CanonicalCode.OK });
    }
    span.end();
    cb.call(this, err, res);
  };
}