How to use the @opentelemetry/types.CanonicalCode.UNKNOWN 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 Azure / azure-sdk-for-js / sdk / identity / identity / src / client / identityClient.ts View on Github external
// It's likely that the refresh token has expired, so
        // return null so that the credential implementation will
        // initiate the authentication flow again.
        logger.info(`IdentityClient: interaction required for client ID: ${clientId}`);
        span.setStatus({
          code: CanonicalCode.UNAUTHENTICATED,
          message: err.message
        });

        return null;
      } else {
        logger.warning(
          `IdentityClient: failed refreshing token for client ID: ${clientId}: ${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 / utils.ts View on Github external
export function handleInvalidQuery(
  this: pgTypes.Client & PgClientExtended,
  tracer: Tracer,
  originalQuery: typeof pgTypes.Client.prototype.query,
  ...args: unknown[]
) {
  let result;
  const span = pgStartSpan(tracer, this, PostgresPlugin.BASE_SPAN_NAME);
  try {
    result = originalQuery.apply(this, args as never);
    span.setStatus({ code: CanonicalCode.OK }); // this will never happen, but set a status anyways
  } catch (e) {
    span.setStatus({ code: CanonicalCode.UNKNOWN, message: e.message });
    throw e;
  } finally {
    span.end();
  }
  return result;
}
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-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 Azure / azure-sdk-for-js / sdk / eventhub / event-hubs / src / sender.ts View on Github external
} 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 Azure / azure-sdk-for-js / sdk / identity / identity / src / credentials / clientSecretCredential.ts View on Github external
}),
        headers: {
          Accept: "application/json",
          "Content-Type": "application/x-www-form-urlencoded"
        },
        abortSignal: options && options.abortSignal,
        spanOptions: newOptions.tracingOptions && newOptions.tracingOptions.spanOptions
      });

      const tokenResponse = await this.identityClient.sendTokenRequest(webResource);
      return (tokenResponse && tokenResponse.accessToken) || null;
    } catch (err) {
      const code =
        err.name === AuthenticationErrorName
          ? CanonicalCode.UNAUTHENTICATED
          : CanonicalCode.UNKNOWN;
      span.setStatus({
        code,
        message: err.message
      });
      throw err;
    } finally {
      span.end();
    }
  }
}
github Azure / azure-sdk-for-js / sdk / identity / identity / src / credentials / deviceCodeCredential.ts View on Github external
spanOptions: newOptions.tracingOptions && newOptions.tracingOptions.spanOptions
      });

      logger.info("DeviceCodeCredential: sending devicecode request");

      const response = await this.identityClient.sendRequest(webResource);
      if (!(response.status === 200 || response.status === 201)) {
        throw new AuthenticationError(response.status, response.bodyAsText);
      }

      return response.parsedBody as DeviceCodeResponse;
    } catch (err) {
      const code =
        err.name === AuthenticationErrorName
          ? CanonicalCode.UNAUTHENTICATED
          : CanonicalCode.UNKNOWN;

      if (err.name === AuthenticationErrorName) {
        logger.warning(
          `DeviceCodeCredential: failed to authenticate ${
            (err as AuthenticationError).errorResponse.errorDescription
          }`
        );
      } else {
        logger.warning(`DeviceCodeCredential: failed to authenticate ${err}`);
      }

      span.setStatus({
        code,
        message: err.message
      });
      throw err;
github open-telemetry / opentelemetry-js / packages / opentelemetry-plugin-grpc / src / utils.ts View on Github external
export const _grpcStatusCodeToCanonicalCode = (
  status?: grpcTypes.status
): CanonicalCode => {
  if (status !== 0 && !status) {
    return CanonicalCode.UNKNOWN;
  }
  return status as number;
};
github Azure / azure-sdk-for-js / sdk / appconfiguration / app-configuration / src / internal / tracingHelpers.ts View on Github external
static getCanonicalCode(err: Error) {
    if (Spanner.isRestError(err)) {
      switch (err.statusCode) {
        case 401:
          return CanonicalCode.PERMISSION_DENIED;
        case 404:
          return CanonicalCode.NOT_FOUND;
        case 412:
          return CanonicalCode.FAILED_PRECONDITION;
      }
    }

    return CanonicalCode.UNKNOWN;
  }