How to use the @opentelemetry/types.SpanKind.CLIENT 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-plugin-redis / src / utils.ts View on Github external
return function internal_send_command_trace(
    this: redisTypes.RedisClient & RedisPluginClientTypes,
    cmd?: RedisCommand
  ) {
    // New versions of redis (2.4+) use a single options object
    // instead of named arguments
    if (arguments.length === 1 && typeof cmd === 'object') {
      const span = tracer.startSpan(`${RedisPlugin.COMPONENT}-${cmd.command}`, {
        kind: SpanKind.CLIENT,
        parent: tracer.getCurrentSpan(),
        attributes: {
          [AttributeNames.COMPONENT]: RedisPlugin.COMPONENT,
          [AttributeNames.DB_STATEMENT]: cmd.command,
        },
      });

      // Set attributes for not explicitly typed RedisPluginClientTypes
      if (this.options) {
        span.setAttributes({
          [AttributeNames.PEER_HOSTNAME]: this.options.host,
          [AttributeNames.PEER_PORT]: this.options.port,
        });
      }
      if (this.address) {
        span.setAttribute(
github open-telemetry / opentelemetry-js / packages / opentelemetry-plugin-grpc / src / grpc.ts View on Github external
const callbackFuncIndex = findIndex(args, arg => {
          return typeof arg === 'function';
        });
        if (callbackFuncIndex !== -1) {
          args[callbackFuncIndex] = patchedCallback(
            span,
            args[callbackFuncIndex],
            metadata
          );
        }
      }

      span.addEvent('sent');
      span.setAttributes({
        [AttributeNames.GRPC_METHOD]: original.path,
        [AttributeNames.GRPC_KIND]: SpanKind.CLIENT,
      });

      this._setSpanContext(metadata, span.context());
      const call = original.apply(self, args);

      // if server stream or bidi
      if (original.responseStream) {
        // Both error and status events can be emitted
        // the first one emitted set spanEnded to true
        let spanEnded = false;
        const endSpan = () => {
          if (!spanEnded) {
            span.end();
            spanEnded = true;
          }
        };
github open-telemetry / opentelemetry-js / packages / opentelemetry-plugin-postgres / opentelemetry-plugin-pg / src / utils.ts View on Github external
function pgStartSpan(
  tracer: Tracer,
  client: pgTypes.Client & PgClientExtended,
  name: string
) {
  const jdbcString = getJDBCString(client.connectionParameters);
  return tracer.startSpan(name, {
    kind: SpanKind.CLIENT,
    parent: tracer.getCurrentSpan(),
    attributes: {
      [AttributeNames.COMPONENT]: PostgresPlugin.COMPONENT, // required
      [AttributeNames.DB_INSTANCE]: client.connectionParameters.database, // required
      [AttributeNames.DB_TYPE]: PostgresPlugin.DB_TYPE, // required
      [AttributeNames.PEER_ADDRESS]: jdbcString, // required
      [AttributeNames.PEER_HOSTNAME]: client.connectionParameters.host, // required
      [AttributeNames.PEER_PORT]: client.connectionParameters.port,
      [AttributeNames.DB_USER]: client.connectionParameters.user,
    },
  });
}
github open-telemetry / opentelemetry-js / packages / opentelemetry-plugin-http / src / http.ts View on Github external
: undefined
      );

      options = optionsParsed;

      if (
        Utils.isOpenTelemetryRequest(options) ||
        Utils.isIgnored(origin + pathname, plugin._config.ignoreOutgoingUrls)
      ) {
        return original.apply(this, [options, ...args]);
      }

      const currentSpan = plugin._tracer.getCurrentSpan();
      const operationName = `${method} ${pathname}`;
      const spanOptions: SpanOptions = {
        kind: SpanKind.CLIENT,
        parent: currentSpan ? currentSpan : undefined,
      };

      const span = plugin._startHttpSpan(operationName, spanOptions);
      plugin._tracer
        .getHttpTextFormat()
        .inject(span.context(), Format.HTTP, options.headers);

      const request: ClientRequest = plugin._safeExecute(span, () =>
        original.apply(this, [options, ...args])
      );

      plugin._logger.debug('%s plugin outgoingRequest', plugin.moduleName);
      plugin._tracer.bind(request);

      // Checks if this outgoing request is part of an operation by checking
github open-telemetry / opentelemetry-js / packages / opentelemetry-plugin-postgres / opentelemetry-plugin-pg-pool / src / pg-pool.ts View on Github external
return function connect(this: PgPoolExtended, callback?: PgPoolCallback) {
        const jdbcString = utils.getJDBCString(this.options);
        // setup span
        const span = plugin._tracer.startSpan(
          `${PostgresPoolPlugin.COMPONENT}.connect`,
          {
            kind: SpanKind.CLIENT,
            parent: plugin._tracer.getCurrentSpan() || undefined,
            attributes: {
              [AttributeNames.COMPONENT]: PostgresPoolPlugin.COMPONENT, // required
              [AttributeNames.DB_TYPE]: PostgresPoolPlugin.DB_TYPE, // required
              [AttributeNames.DB_INSTANCE]: this.options.database, // required
              [AttributeNames.PEER_HOSTNAME]: this.options.host, // required
              [AttributeNames.PEER_ADDRESS]: jdbcString, // required
              [AttributeNames.PEER_PORT]: this.options.port,
              [AttributeNames.DB_USER]: this.options.user,
              [AttributeNames.IDLE_TIMEOUT_MILLIS]: this.options
                .idleTimeoutMillis,
              [AttributeNames.MAX_CLIENT]: this.options.maxClient,
            },
          }
        );
github Azure / azure-sdk-for-js / sdk / core / core-http / lib / policies / tracingPolicy.ts View on Github external
public async sendRequest(request: WebResource): Promise {
    if (!request.spanOptions || !request.spanOptions.parent) {
      return this._nextPolicy.sendRequest(request);
    }

    // create a new span
    const tracer = getTracer();
    const spanOptions: SpanOptions = {
      ...request.spanOptions,
      kind: SpanKind.CLIENT
    };
    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();
github open-telemetry / opentelemetry-js / packages / opentelemetry-plugin-mongodb-core / src / mongodb.ts View on Github external
if (
          currentSpan === undefined ||
          typeof resultHandler !== 'function' ||
          typeof commands !== 'object'
        ) {
          return original.apply(this, (arguments as unknown) as unknown[]);
        }
        const command = commands instanceof Array ? commands[0] : commands;
        const commandType = plugin._getCommandType(command);
        const type =
          commandType === MongodbCommandType.UNKNOWN
            ? operationName
            : commandType;
        const span = plugin._tracer.startSpan(`mongodb.${type}`, {
          parent: currentSpan,
          kind: SpanKind.CLIENT,
        });
        plugin._populateAttributes(
          span,
          ns,
          command,
          this as MongoInternalTopology
        );
        return original.call(
          this,
          ns,
          commands,
          plugin._patchEnd(span, resultHandler)
        );
      };
    };
github open-telemetry / opentelemetry-js / packages / opentelemetry-plugin-dns / src / dns.ts View on Github external
private _startDnsSpan(name: string, options: Omit) {
    return this._tracer
      .startSpan(name, { ...options, kind: SpanKind.CLIENT })
      .setAttribute(AttributeNames.COMPONENT, this.component);
  }
github open-telemetry / opentelemetry-js / packages / opentelemetry-plugin-grpc / src / grpc.ts View on Github external
return function clientMethodTrace(this: grpcTypes.Client) {
        const name = `grpc.${original.path.replace('/', '')}`;
        const args = Array.prototype.slice.call(arguments);
        const span = plugin._tracer
          .startSpan(name, {
            kind: SpanKind.CLIENT,
            parent: plugin._tracer.getCurrentSpan(),
          })
          .setAttribute(AttributeNames.COMPONENT, GrpcPlugin.component);
        return plugin._makeGrpcClientRemoteCall(
          original,
          args,
          this,
          plugin
        )(span);
      };
    };
github Azure / azure-sdk-for-js / sdk / eventhub / event-hubs / src / sender.ts View on Github external
private _createSendSpan(
    parentSpan?: Span | SpanContext,
    spanContextsToLink: SpanContext[] = []
  ): Span {
    const links: Link[] = spanContextsToLink.map((spanContext) => {
      return {
        spanContext
      };
    });
    const tracer = getTracer();
    const span = tracer.startSpan("Azure.EventHubs.send", {
      kind: SpanKind.CLIENT,
      parent: parentSpan,
      links
    });

    span.setAttribute("message_bus.destination", this._eventHubName);
    span.setAttribute("peer.address", this._endpoint);

    return span;
  }