Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrating doc draft #169

Merged
merged 14 commits into from
Jul 23, 2021
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Temporary Items

### Node ###
# Logs
logs
/logs
*.log
npm-debug.log*
yarn-debug.log*
Expand Down
144 changes: 144 additions & 0 deletions MIGRATING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
# Migrate from the SignalFx Tracing Library for NodeJS

The Splunk Distribution of OpenTelemetry for NodeJS replaces the SignalFx Tracing
Library for NodeJS. If you’re using the SignalFx Tracing Library, migrate to
the Splunk Distribution of OpenTelemetry for NodeJS to use OpenTelemetry’s
jtmal-signalfx marked this conversation as resolved.
Show resolved Hide resolved
instrumentation to send traces to Splunk APM. The Splunk Distribution of
OpenTelemetry for NodeJS uses OpenTelemetry to instrument applications, which is
an open-source API to gather telemetry data, and has a smaller footprint.

Because the SignalFx Tracing Library for NodeJS uses OpenTracing and the Splunk Distribution
of OpenTelemetry for NodeJS uses OpenTelemetry, the semantic
conventions for span tag names change when you migrate. For more information,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.. and the span names as well! There are different guidelines for that in OTel.

see [Migrate from OpenTracing to OpenTelemetry](https://docs.signalfx.com/en/latest/apm/apm-getting-started/apm-opentelemetry-collector.html#apm-opentelemetry-migration).

<a name="known-limitations"></a>
## Known limitations as compared to SignalFx Tracing Library

- Lowest supported version of NodeJS is `v8.5`, [see more information here](https://github.com/open-telemetry/opentelemetry-js#node-support)
- No auto-instrumentation for:
- `AdonisJS`
- `amqp10`
- `mongodb-core` ([because it's deprecated](https://github.com/mongodb-js/mongodb-core))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would stress that MongoDB driver auto instrumentation is still supported. They just reogranized the client lib.

- `sails`
- Limited instrumentation for:
- `nest` - only manual insturmentation helpers, provided by community
- other notes on instrumentation:
- `express` instrumentation requires `http`/`https` instrumentation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same applies for koa and hapi for now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh... and it's duplicated few lines below.

- `bluebird` - context propagation only (via `async_hooks`)
- `q` - context propagation only (via `async_hooks`)
jtmalinowski marked this conversation as resolved.
Show resolved Hide resolved
- `when` - context propagation only (via `async_hooks`)
- `socket.io` - provided by community (<https://github.com/aspecto-io/opentelemetry-ext-js/tree/master/packages/instrumentation-socket.io>)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we should talk of limitations. We want people to migrate, not to stick to the old stuff.

Can we change this section so that it states what the Splunk OTel dist for NodeJS is compatible with?

Copy link
Contributor Author

@jtmalinowski jtmalinowski Jul 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Obviously we'll do our best to help the customers migrate, but let's make it clear what the pitfalls are.


## Requirements

This Splunk Distribution of OpenTelemetry requires Node.js 8.5 or later.
jtmalinowski marked this conversation as resolved.
Show resolved Hide resolved
If you're still using an earlier version of Node.js, continue using the SignalFx Tracing Library for Node.js.

## Equivalent configurations
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## Equivalent configurations
## Configurations you can migrate


### Changes to defaults

- Default flush interval, which defines how frequently captured telemetry data is sent to the backend, is now 30s instead of 2s

### Instrumented libraries

With the exception of [explicitly listed limitations](#known-limitations) we aim to support all libraries supported by
signalfx-nodejs-tracing. To find an equivalent auto-instrumentation open <https://opentelemetry.io/registry/> and for
Comment on lines +53 to +54
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto. Consider removing mention of limitations.

each instrumentation
[from `signalfx-nodejs-tracing`'s README](https://github.com/signalfx/signalfx-nodejs-tracing/#requirements-and-supported-software)
search by the name of the library in the registry.

For example, if you'd like to migrate instrumentation for `mysql`, go to
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
For example, if you'd like to migrate instrumentation for `mysql`, go to
For example, if you'd like to migrate instrumentation for MySQL, go to

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, actually, this is how the package is called, see https://www.npmjs.com/package/mysql. Maybe I should convert it into a link and then it'll be clearer?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's OK to keep it like that then

[https://opentelemetry.io/registry/?s=**mysql**&component=&language=**js**#](https://opentelemetry.io/registry/?s=mysql&component=&language=js#).

Once you have identified an instrumentation package, install it using `npm` or `yarn`.

- If the package is [on this list](./README.md#default-instrumentation-packages-), it
will be enabled automatically.
jtmalinowski marked this conversation as resolved.
Show resolved Hide resolved
- if it's not on the list, follow the steps for
[installing other instrumentation packages](./README.md#custom-instrumentation-packages).

### Environment variables

Rename environment variables:

| Old environment variable | New environment variable | notes |
| ---------------------------------- | ------------------------------------ | ----- |
| SIGNALFX_ACCESS_TOKEN | SPLUNK_ACCESS_TOKEN | |
| SIGNALFX_SERVICE_NAME | OTEL_SERVICE_NAME | |
| SIGNALFX_ENDPOINT_URL | OTEL_EXPORTER_JAEGER_ENDPOINT | if Jaeger is used |
| SIGNALFX_ENDPOINT_URL | n/a | OTLP is not implemented yet |
| SIGNALFX_RECORDED_VALUE_MAX_LENGTH | SPLUNK_MAX_ATTR_LENGTH | |
| SIGNALFX_TRACING_DEBUG | no direct equivalent | see [instrumentation logs](#instrumentation-logs) |
| SIGNALFX_SPAN_TAGS | OTEL_RESOURCE_ATTRIBUTES | format needs to be changed to `key1=val1,key2=val2` |
| SIGNALFX_LOGS_INJECTION | SPLUNK_LOGS_INJECTION | |
| SIGNALFX_LOGS_INJECTION_TAGS | OTEL_RESOURCE_ATTRIBUTES | there's no direct equivalent, but values specified in `OTEL_RESOURCE_ATTRIBUTES` will also be used for logs injection |
| SIGNALFX_ENABLED_PLUGINS | n/a | see [the README section about instrumentations](./README.md#custom-instrumentation-packages) |
| SIGNALFX_SERVER_TIMING_CONTEXT | SPLUNK_TRACE_RESPONSE_HEADER_ENABLED | |
| SIGNALFX_TRACING_ENABLED | OTEL_TRACE_ENABLED | |

### Programmatic configuration

| Old property | New property | Notes |
jtmalinowski marked this conversation as resolved.
Show resolved Hide resolved
| ------------------------ | ----------------------- | ----- |
| `service` | `serviceName` | |
| `url` | `endpoint` | |
| `accessToken` | `accessToken` | |
| `enabled` | - | no equivalent, but Environment Variable can be used |
| `debug` | - | no direct equivalent, see [instrumentation logs](#instrumentation-logs) |
| `tags` | `tracerConfig.resource` | |
| `logInjection` | `logInjectionEnabled` | |
| `logInjectionTags` | - | no direct equivalent, but `tracerConfig.resource` can be used |
| `flushInterval` | - | no direct equivalent, contact us if you had customized this value |
| `plugins` | - | see [the README section about instrumentations](./README.md#custom-instrumentation-packages) |
| `recordedValueMaxLength` | `maxAttrLength` | |
| `enableServerTiming` | `serverTimingEnabled` | |

### Invocation

```javascript
const tracer = require('signalfx-tracing').init({
// your options here
})
```

becomes

```javascript
const { startTracing } = require('@splunk/otel');

startTracing({
// your new options here
});
```

and requires installing `@splunk/otel` first, using either NPM or Yarn. Same as in `signalfx-nodejs-tracing`, this code
jtmalinowski marked this conversation as resolved.
Show resolved Hide resolved
is to be run before your `import` or `require` statements.

Alternatively, you can append the flag `-r @splunk/otel/instrument` instead when launching `node` (it runs
`startTracing` under the hood). In that case you cannot use programmatic configuration and must rely on environment
variables only.

### Instrumentation logs

There isn't a one-to-one mapping for `SIGNALFX_TRACING_DEBUG`. The closest equivalent is `OTEL_LOG_LEVEL`, however the logged
information might be different.

> Note that this section is about the logs produced by instrumentation, and not
about the logs produced by the application.

Logging level is controlled by the `OTEL_LOG_LEVEL` environment variable. The two most common values are:
- `INFO`: the default value
- `VERBOSE`: highest value likely to be needed

For all possible log levels see
[this source file](https://github.com/open-telemetry/opentelemetry-js-api/blob/main/src/diag/types.ts).

There is no default output for logs. Even if you set `OTEL_LOG_LEVEL=VERBOSE`, nothing is output to the console. You need to set an output first, for example to `stdout`, by adding `DiagConsoleLogger`:

```js
const { diag, DiagConsoleLogger, DiagLogLevel } = require("@opentelemetry/api");

diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.ALL);
```
33 changes: 22 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
# Splunk distribution of OpenTelemetry JS
<p align="center">
<img alt="Beta" src="https://img.shields.io/badge/status-beta-informational?style=for-the-badge">
<a href="https://github.com/signalfx/splunk-otel-js/releases">
<img alt="GitHub release (latest by date)" src="https://img.shields.io/github/v/release/signalfx/splunk-otel-js?include_prereleases&style=for-the-badge">
</a>
<img alt="Codecov" src="https://img.shields.io/codecov/c/github/signalfx/splunk-otel-js?style=for-the-badge&token=XKXjEQKGaK">
<img alt="GitHub branch checks state" src="https://img.shields.io/github/checks-status/signalfx/splunk-otel-js/main?style=for-the-badge">
</p>

[![CircleCI](https://circleci.com/gh/signalfx/splunk-otel-js.svg?style=svg)](https://circleci.com/gh/signalfx/splunk-otel-js)
[![codecov](https://codecov.io/gh/signalfx/splunk-otel-js/branch/main/graph/badge.svg?token=XKXjEQKGaK)](https://codecov.io/gh/signalfx/splunk-otel-js)
# Splunk distribution of OpenTelemetry JS for NodeJS

The Splunk distribution of [OpenTelemetry
JS](https://github.com/open-telemetry/opentelemetry-js) provides
multiple installable packages that automatically instruments your Node
multiple installable packages that automatically instruments your Node
application to capture and report distributed traces to Splunk APM.

This Splunk distribution comes with the following defaults:
Expand All @@ -21,7 +27,7 @@ This Splunk distribution comes with the following defaults:

If you're currently using the SignalFx Tracing Library for Node and want to
migrate to the Splunk Distribution of OpenTelemetry Node, see [Migrate from
the SignalFx Tracing Library for JS](migration.md).
the SignalFx Tracing Library for JS](./MIGRATING.md).

> :construction: This project is currently in **BETA**. It is **officially supported** by Splunk. However, breaking changes **MAY** be introduced.

Expand Down Expand Up @@ -116,7 +122,7 @@ In order to send traces directly to SignalFx ingest API, you need to:
## Automatically instrument an application

You can use node's `-r` CLI flag to pre-load the instrumentation module and automatically instrument your NodeJS application.
You can add `-r @splunk/otel/instrument` CLI parameter to automatically instrument your application.
You can add `-r @splunk/otel/instrument` CLI parameter to automatically instrument your application.

For example, if you start your application as follows:

Expand Down Expand Up @@ -217,20 +223,25 @@ By default the following instrumentations will automatically be enabled if they
any of these instrumentations, you'll need to install them with npm and then run your app with `-r @splunk/otel/instrument` flag as described above.

```
@opentelemetry/instrumentation-http
@opentelemetry/instrumentation-dns
@opentelemetry/instrumentation-express
@opentelemetry/instrumentation-graphql
@opentelemetry/instrumentation-grpc
@opentelemetry/instrumentation-koa
@opentelemetry/instrumentation-express
@opentelemetry/instrumentation-hapi
@opentelemetry/instrumentation-http
@opentelemetry/instrumentation-ioredis
@opentelemetry/instrumentation-koa
@opentelemetry/instrumentation-mongodb
@opentelemetry/instrumentation-mysql
@opentelemetry/instrumentation-net
@opentelemetry/instrumentation-pg
@opentelemetry/instrumentation-hapi
opentelemetry-instrumentation-amqplib
opentelemetry-instrumentation-aws-sdk
opentelemetry-instrumentation-elasticsearch
opentelemetry-instrumentation-kafkajs
opentelemetry-instrumentation-mongoose
opentelemetry-instrumentation-sequelize
opentelemetry-instrumentation-typeorm
```

If log injection is enabled, the corresponding logging library package will need to be installed beforehand. Supported logging library instrumentations:
Expand All @@ -241,7 +252,7 @@ If log injection is enabled, the corresponding logging library package will need
@opentelemetry/instrumentation-winston
```

You can find more instrumentation packages over at the [OpenTelemetry Registry](https://opentelemetry.io/registry/?language=js) and enable them manually
You can find more instrumentation packages over at the [OpenTelemetry Registry](https://opentelemetry.io/registry/?language=js) and enable them manually
as described above.

## Troubleshooting
Expand Down
2 changes: 2 additions & 0 deletions examples/logs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
package-lock.json
17 changes: 17 additions & 0 deletions examples/logs/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const { diag, DiagConsoleLogger } = require("@opentelemetry/api");
const { NodeTracerProvider } = require("@opentelemetry/node");
const { registerInstrumentations } = require("@opentelemetry/instrumentation");
const { HttpInstrumentation } = require("@opentelemetry/instrumentation-http");
const { getEnv } = require("@opentelemetry/core");

// TODO: this is quite inconvenient
diag.setLogger(new DiagConsoleLogger(), getEnv().OTEL_LOG_LEVEL);

const provider = new NodeTracerProvider();
provider.register();

registerInstrumentations({
instrumentations: [
new HttpInstrumentation(),
],
});
6 changes: 6 additions & 0 deletions examples/logs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"dependencies": {
"@opentelemetry/api": "^1.0.1",
"@splunk/otel": "^0.9.0"
}
}
16 changes: 16 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,20 @@
},
"peerDependencies": {
"@opentelemetry/instrumentation-bunyan": "^0.23.0",
"@opentelemetry/instrumentation-cassandra-driver": "^0.23.0",
"@opentelemetry/instrumentation-dns": "^0.23.0",
"@opentelemetry/instrumentation-express": "^0.23.0",
"@opentelemetry/instrumentation-graphql": "^0.23.0",
"@opentelemetry/instrumentation-grpc": "^0.23.0",
"@opentelemetry/instrumentation-hapi": "^0.23.0",
"@opentelemetry/instrumentation-http": "^0.23.0",
"@opentelemetry/instrumentation-ioredis": "^0.23.0",
"@opentelemetry/instrumentation-knex": "^0.23.0",
"@opentelemetry/instrumentation-koa": "^0.23.0",
"@opentelemetry/instrumentation-memcached": "^0.23.0",
"@opentelemetry/instrumentation-mongodb": "^0.23.0",
"@opentelemetry/instrumentation-mysql": "^0.23.0",
"@opentelemetry/instrumentation-mysql2": "^0.23.0",
"@opentelemetry/instrumentation-net": "^0.23.0",
"@opentelemetry/instrumentation-pg": "^0.23.0",
"@opentelemetry/instrumentation-pino": "^0.23.0",
Expand Down Expand Up @@ -185,6 +189,18 @@
},
"opentelemetry-instrumentation-mongoose": {
"optional": true
},
"@opentelemetry/instrumentation-cassandra-driver": {
"optional": true
},
"@opentelemetry/instrumentation-knex": {
"optional": true
},
"@opentelemetry/instrumentation-memcached": {
"optional": true
},
"@opentelemetry/instrumentation-mysql2": {
"optional": true
}
}
}
26 changes: 19 additions & 7 deletions src/instrumentations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,44 @@ import { InstrumentationOption } from '@opentelemetry/instrumentation';

import { load } from './loader';

// please keep the list sorted alphabetically
// please update ../../README.md#default-instrumentation-packages when changing this list
// please check if ../../MIGRATING.md#known-limitations needs to be updated when changing this list
const supportedInstrumentations: [string, string][] = [
['@opentelemetry/instrumentation-http', 'HttpInstrumentation'],
['@opentelemetry/instrumentation-bunyan', 'BunyanInstrumentation'],
[
'@opentelemetry/instrumentation-cassandra-driver',
'CassandraDriverInstrumentation',
],
['@opentelemetry/instrumentation-dns', 'DnsInstrumentation'],
['@opentelemetry/instrumentation-express', 'ExpressInstrumentation'],
['@opentelemetry/instrumentation-graphql', 'GraphQLInstrumentation'],
['@opentelemetry/instrumentation-grpc', 'GrpcInstrumentation'],
['@opentelemetry/instrumentation-koa', 'KoaInstrumentation'],
['@opentelemetry/instrumentation-express', 'ExpressInstrumentation'],
['@opentelemetry/instrumentation-hapi', 'HapiInstrumentation'],
['@opentelemetry/instrumentation-http', 'HttpInstrumentation'],
['@opentelemetry/instrumentation-ioredis', 'IORedisInstrumentation'],
['@opentelemetry/instrumentation-knex', 'KnexInstrumentation'],
['@opentelemetry/instrumentation-koa', 'KoaInstrumentation'],
['@opentelemetry/instrumentation-memcached', 'MemcachedInstrumentation'],
['@opentelemetry/instrumentation-mongodb', 'MongoDBInstrumentation'],
['@opentelemetry/instrumentation-mysql', 'MySQLInstrumentation'],
['@opentelemetry/instrumentation-mysql2', 'MySQL2Instrumentation'],
['@opentelemetry/instrumentation-net', 'NetInstrumentation'],
['@opentelemetry/instrumentation-pg', 'PgInstrumentation'],
['@opentelemetry/instrumentation-hapi', 'HapiInstrumentation'],
['@opentelemetry/instrumentation-bunyan', 'BunyanInstrumentation'],
['@opentelemetry/instrumentation-pino', 'PinoInstrumentation'],
['@opentelemetry/instrumentation-redis', 'RedisInstrumentation'],
['@opentelemetry/instrumentation-restify', 'RestifyInstrumentation'],
['@opentelemetry/instrumentation-winston', 'WinstonInstrumentation'],
['opentelemetry-instrumentation-amqplib', 'AmqplibInstrumentation'],
['opentelemetry-instrumentation-aws-sdk', 'AwsInstrumentation'],
[
'opentelemetry-instrumentation-elasticsearch',
'ElasticsearchInstrumentation',
],
['opentelemetry-instrumentation-aws-sdk', 'AwsInstrumentation'],
['opentelemetry-instrumentation-kafkajs', 'KafkaJsInstrumentation'],
['opentelemetry-instrumentation-mongoose', 'MongooseInstrumentation'],
['opentelemetry-instrumentation-sequelize', 'SequelizeInstrumentation'],
['opentelemetry-instrumentation-typeorm', 'TypeormInstrumentation'],
['opentelemetry-instrumentation-mongoose', 'MongooseInstrumentation'],
];

export function getInstrumentations(): InstrumentationOption[] {
Expand Down
9 changes: 6 additions & 3 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* limitations under the License.
*/

import { env } from 'process';
import { SpanExporter, SpanProcessor } from '@opentelemetry/tracing';
import { InstrumentationOption } from '@opentelemetry/instrumentation';
import { B3Propagator, B3InjectEncoding } from '@opentelemetry/propagator-b3';
Expand Down Expand Up @@ -84,16 +83,20 @@ export function _setDefaultOptions(options: Partial<Options> = {}): Options {
options.logInjectionEnabled = getEnvBoolean('SPLUNK_LOGS_INJECTION', false);
}

const otelEnv = getEnv();

options.endpoint =
options.endpoint || env.OTEL_EXPORTER_JAEGER_ENDPOINT || defaultEndpoint;
options.endpoint ||
otelEnv.OTEL_EXPORTER_JAEGER_ENDPOINT ||
defaultEndpoint;

const extraTracerConfig = options.tracerConfig || {};

let resource = new EnvResourceDetector().detect();

const serviceName =
options.serviceName ||
getEnv().OTEL_SERVICE_NAME ||
otelEnv.OTEL_SERVICE_NAME ||
resource.attributes[ResourceAttributes.SERVICE_NAME] ||
defaultServiceName;

Expand Down
Loading