@google-cloud/opentelemetry-cloud-trace-exporter
TypeScript icon, indicating that this package has built-in type declarations

2.1.0 • Public • Published

OpenTelemetry Google Cloud Trace Exporter

NPM Published Version Apache License

OpenTelemetry Google Cloud Trace Exporter allows the user to send collected traces to Google Cloud.

Google Cloud Trace is a distributed tracing system. It helps gather timing data needed to troubleshoot latency problems in microservice architectures. It manages both the collection and lookup of this data.

Setup

Google Cloud Trace is a managed service provided by Google Cloud Platform.

Installation

npm install --save @google-cloud/opentelemetry-cloud-trace-exporter

Usage

Install the exporter on your application, register the exporter, and start tracing. If you are running in a GCP environment, the exporter will automatically authenticate using the environment's service account. If not, you will need to follow the instructions in Authentication.

const { TraceExporter } = require('@google-cloud/opentelemetry-cloud-trace-exporter');

const exporter = new TraceExporter({
  // If you are not in a GCP environment, you will need to provide your
  // service account key here. See the Authentication section below.
});

Now, register the exporter.

provider.addSpanProcessor(new BatchSpanProcessor(exporter));

You can use built-in SimpleSpanProcessor or BatchSpanProcessor or write your own.

  • SimpleSpanProcessor: The implementation of SpanProcessor that passes ended span directly to the configured SpanExporter.
  • BatchSpanProcessor: The implementation of the SpanProcessor that batches ended spans and pushes them to the configured SpanExporter. It is recommended to use this SpanProcessor for better performance and optimization.

Resource attributes

By default, OpenTelemetry resource attributes which do not map to a monitored resource are ignored. If you wish to export other resource attributes, you must specify a regexp that should match the attribute keys you'd like.

For example, if you are setting up a resource with the "service" semantic attributes:

const { SemanticResourceAttributes } = require('@opentelemetry/semantic-conventions');

const provider = new NodeTracerProvider({
  // ...
  resource: new Resource({
    [SemanticResourceAttributes.SERVICE_NAME]: 'things-service',
    [SemanticResourceAttributes.SERVICE_NAMESPACE]: 'things',
    [SemanticResourceAttributes.SERVICE_VERSION]: '1.0.0',
    [SemanticResourceAttributes.SERVICE_INSTANCE_ID]: 'abc123',
  }),
})

You can ensure they are exported by using a regexp that matches them:

const exporter = new TraceExporter({
  // will export all resource attributes that start with "service."
  resourceFilter: /^service\./
});

Authentication

The Google Cloud Trace exporter supports authentication using service accounts. These can either be defined in a keyfile (usually called service_account_key.json or similar), or by the environment. If your application runs in a GCP environment, such as Compute Engine, you don't need to provide any application credentials. The client library will find the credentials by itself. For more information, go to https://cloud.google.com/docs/authentication/.

Service account key

If you are not running in a GCP environment, you will need to give the service account credentials to the exporter.

const { TraceExporter } = require('@google-cloud/opentelemetry-cloud-trace-exporter');

const exporter = new TraceExporter({
  /** option 1. provide a service account key json */
  keyFile: './service_account_key.json',
  keyFileName: './service_account_key.json',

  /** option 2. provide credentials directly */
  credentials: {
    client_email: string,
    private_key: string,
  },
});

Useful links

Package Sidebar

Install

npm i @google-cloud/opentelemetry-cloud-trace-exporter

Weekly Downloads

83,370

Version

2.1.0

License

Apache-2.0

Unpacked Size

45.2 kB

Total Files

15

Last publish

Collaborators

  • google-wombot
  • google-admin