Skip to content

Commit

Permalink
Merge branch 'main' into issue-561
Browse files Browse the repository at this point in the history
  • Loading branch information
vmarchaud committed Jul 12, 2021
2 parents 3ebf81d + 902c91f commit 1540bd0
Show file tree
Hide file tree
Showing 25 changed files with 263 additions and 151 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Expand Up @@ -4,6 +4,7 @@
# JavaScript, TypeScript, c, and h source files
*.js text eol=lf
*.ts text eol=lf
*.tsx text eol=lf
*.h text eol=lf diff=cpp
*.c text eol=lf diff=cpp

Expand Down
33 changes: 27 additions & 6 deletions metapackages/auto-instrumentations-node/README.md
Expand Up @@ -5,35 +5,43 @@
[![devDependencies][devDependencies-image]][devDependencies-url]
[![Apache License][license-image]][license-url]

This module provides a simple way to initialize multiple Node instrumentations.

## Installation

```bash
npm install --save @opentelemetry/auto-instrumentations-node
```

## Usage
OpenTelemetry Meta Packages for Node automatically loads instrumentations for Node builtin modules and common packages.

Custom configuration for each of the instrumentations can be passed to the function, by providing an object with the name of the instrumentation as a key, and its configuration as the value.

```javascript
const { NodeTracerProvider } = require('@opentelemetry/node');
const { getNodeAutoInstrumentations } = require('@opentelemetry/auto-instrumentations-node');
const { CollectorTraceExporter } = require('@opentelemetry/exporter-collector');
const { Resource } = require('@opentelemetry/resources');
const { ResourceAttributes } = require('@opentelemetry/semantic-conventions');
const { SimpleSpanProcessor } = require('@opentelemetry/tracing');
const { registerInstrumentations } = require('@opentelemetry/instrumentation');

const exporter = new CollectorTraceExporter({
serviceName: 'auto-instrumentations-node',
const exporter = new CollectorTraceExporter();
const provider = new NodeTracerProvider({
resource: new Resource({
[ResourceAttributes.SERVICE_NAME]: 'basic-service',
}),
});

const provider = new NodeTracerProvider();
provider.addSpanProcessor(new SimpleSpanProcessor(exporter));
provider.register();

registerInstrumentations({
instrumentations: [
getNodeAutoInstrumentations({
// load custom configuration for http instrumentation
"@opentelemetry/instrumentation-http": {
applyCustomAttributesOnSpan: (span)=> {
'@opentelemetry/instrumentation-http': {
applyCustomAttributesOnSpan: (span) => {
span.setAttribute('foo2', 'bar2');
},
},
Expand All @@ -42,6 +50,19 @@ registerInstrumentations({
});

```
## Supported instrumentations

- [@opentelemetry/instrumentation-dns](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-dns)
- [@opentelemetry/instrumentation-http](https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-instrumentation-http)
- [@opentelemetry/instrumentation-grpc](https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-instrumentation-grpc)
- [@opentelemetry/instrumentation-express](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-express)
- [@opentelemetry/instrumentation-koa](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-koa)
- [@opentelemetry/instrumentation-graphql](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-graphql)
- [@opentelemetry/instrumentation-ioredis](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-ioredis)
- [@opentelemetry/instrumentation-redis](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-redis)
- [@opentelemetry/instrumentation-pg](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-pg)
- [@opentelemetry/instrumentation-mongodb](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-mongodb)
- [@opentelemetry/instrumentation-mysql](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/plugins/node/opentelemetry-instrumentation-mysql)

## Useful links

Expand Down
Expand Up @@ -71,11 +71,11 @@ export const traceContextEnvironmentKey = '_X_AMZN_TRACE_ID';
export class AwsLambdaInstrumentation extends InstrumentationBase {
private _tracerProvider: TracerProvider | undefined;

constructor(protected _config: AwsLambdaInstrumentationConfig = {}) {
constructor(protected override _config: AwsLambdaInstrumentationConfig = {}) {
super('@opentelemetry/instrumentation-aws-lambda', VERSION, _config);
}

setConfig(config: AwsLambdaInstrumentationConfig = {}) {
override setConfig(config: AwsLambdaInstrumentationConfig = {}) {
this._config = config;
}

Expand Down Expand Up @@ -221,7 +221,7 @@ export class AwsLambdaInstrumentation extends InstrumentationBase {
};
}

setTracerProvider(tracerProvider: TracerProvider) {
override setTracerProvider(tracerProvider: TracerProvider) {
super.setTracerProvider(tracerProvider);
this._tracerProvider = tracerProvider;
}
Expand Down
Expand Up @@ -67,11 +67,11 @@ export class BunyanInstrumentation extends InstrumentationBase<
];
}

getConfig(): BunyanInstrumentationConfig {
override getConfig(): BunyanInstrumentationConfig {
return this._config;
}

setConfig(config: BunyanInstrumentationConfig) {
override setConfig(config: BunyanInstrumentationConfig) {
this._config = config;
}

Expand Down
Expand Up @@ -37,7 +37,7 @@ import { VERSION } from './version';
* Dns instrumentation for Opentelemetry
*/
export class DnsInstrumentation extends InstrumentationBase<Dns> {
constructor(protected _config: DnsInstrumentationConfig = {}) {
constructor(protected override _config: DnsInstrumentationConfig = {}) {
super('@opentelemetry/instrumentation-dns', VERSION, _config);
}

Expand Down
Expand Up @@ -77,7 +77,7 @@ export class GraphQLInstrumentation extends InstrumentationBase {
return this._config as GraphQLInstrumentationParsedConfig;
}

setConfig(config: GraphQLInstrumentationConfig & InstrumentationConfig = {}) {
override setConfig(config: GraphQLInstrumentationConfig = {}) {
this._config = Object.assign({}, DEFAULT_CONFIG, config);
}

Expand Down
Expand Up @@ -43,7 +43,7 @@ export class Instrumentation extends InstrumentationBase<typeof Memcached> {
);
}

setConfig(config: InstrumentationConfig = {}) {
override setConfig(config: InstrumentationConfig = {}) {
this._config = Object.assign({}, Instrumentation.DEFAULT_CONFIG, config);
}

Expand Down
Expand Up @@ -15,4 +15,8 @@
*/

export * from './instrumentation';
export { MongoDBInstrumentationConfig } from './types';
export {
MongoDBInstrumentationConfig,
MongoDBInstrumentationExecutionResponseHook,
MongoResponseHookInformation,
} from './types';
Expand Up @@ -48,7 +48,7 @@ const supportedVersions = ['>=3.3 <4'];
export class MongoDBInstrumentation extends InstrumentationBase<
typeof mongodb
> {
constructor(protected _config: MongoDBInstrumentationConfig = {}) {
constructor(protected override _config: MongoDBInstrumentationConfig = {}) {
super('@opentelemetry/instrumentation-mongodb', VERSION, _config);
}

Expand Down
Expand Up @@ -42,8 +42,8 @@ export class MySQLInstrumentation extends InstrumentationBase<
[SemanticAttributes.DB_SYSTEM]: MySQLInstrumentation.COMPONENT,
};

constructor(protected _config: MySQLInstrumentationConfig = {}) {
super('@opentelemetry/instrumentation-mysql', VERSION, _config);
constructor(config?: MySQLInstrumentationConfig) {
super('@opentelemetry/instrumentation-mysql', VERSION, config);
}

protected init() {
Expand Down
Expand Up @@ -41,8 +41,8 @@ export class MySQL2Instrumentation extends InstrumentationBase<
[SemanticAttributes.DB_SYSTEM]: MySQL2Instrumentation.COMPONENT,
};

constructor(protected _config: MySQL2InstrumentationConfig = {}) {
super('@opentelemetry/instrumentation-mysql2', VERSION, _config);
constructor(config?: MySQL2InstrumentationConfig) {
super('@opentelemetry/instrumentation-mysql2', VERSION, config);
}

protected init() {
Expand Down
Expand Up @@ -33,7 +33,7 @@ import { Socket } from 'net';
import { TLSSocket } from 'tls';

export class NetInstrumentation extends InstrumentationBase<Net> {
constructor(protected _config: InstrumentationConfig = {}) {
constructor(_config?: InstrumentationConfig) {
super('@opentelemetry/instrumentation-net', VERSION, _config);
}

Expand Down
Expand Up @@ -82,20 +82,20 @@ export class PinoInstrumentation extends InstrumentationBase {
];
}

getConfig(): PinoInstrumentationConfig {
override getConfig(): PinoInstrumentationConfig {
return this._config;
}

setConfig(config: PinoInstrumentationConfig) {
override setConfig(config: PinoInstrumentationConfig) {
this._config = config;
}

enable() {
override enable() {
super.enable();
this._isEnabled = true;
}

disable() {
override disable() {
super.disable();
this._isEnabled = false;
}
Expand Down
Expand Up @@ -38,11 +38,11 @@ export class RedisInstrumentation extends InstrumentationBase<
> {
static readonly COMPONENT = 'redis';

constructor(protected _config: RedisInstrumentationConfig = {}) {
constructor(protected override _config: RedisInstrumentationConfig = {}) {
super('@opentelemetry/instrumentation-redis', VERSION, _config);
}

setConfig(config: RedisInstrumentationConfig = {}) {
override setConfig(config: RedisInstrumentationConfig = {}) {
this._config = Object.assign({}, DEFAULT_CONFIG, config);
}

Expand Down
Expand Up @@ -102,11 +102,11 @@ export class WinstonInstrumentation extends InstrumentationBase {
];
}

getConfig(): WinstonInstrumentationConfig {
override getConfig(): WinstonInstrumentationConfig {
return this._config;
}

setConfig(config: WinstonInstrumentationConfig) {
override setConfig(config: WinstonInstrumentationConfig) {
this._config = config;
}

Expand Down
Expand Up @@ -48,7 +48,6 @@ export class DocumentLoadInstrumentation extends InstrumentationBase<unknown> {
readonly component: string = 'document-load';
readonly version: string = '1';
moduleName = this.component;
protected _config!: InstrumentationConfig;

/**
*
Expand Down Expand Up @@ -235,7 +234,7 @@ export class DocumentLoadInstrumentation extends InstrumentationBase<unknown> {
/**
* implements enable function
*/
enable() {
override enable() {
// remove previously attached load to avoid adding the same event twice
// in case of multiple enable calling.
window.removeEventListener('load', this._onDocumentLoaded);
Expand All @@ -245,7 +244,7 @@ export class DocumentLoadInstrumentation extends InstrumentationBase<unknown> {
/**
* implements disable function
*/
disable() {
override disable() {
window.removeEventListener('load', this._onDocumentLoaded);
}
}
Expand Up @@ -530,7 +530,7 @@ export class UserInteractionInstrumentation extends InstrumentationBase<unknown>
/**
* implements enable function
*/
enable() {
override enable() {
const ZoneWithPrototype = this.getZoneWithPrototype();
api.diag.debug(
'applying patch to',
Expand Down Expand Up @@ -599,7 +599,7 @@ export class UserInteractionInstrumentation extends InstrumentationBase<unknown>
/**
* implements unpatch function
*/
disable() {
override disable() {
const ZoneWithPrototype = this.getZoneWithPrototype();
api.diag.debug(
'removing patch from',
Expand Down
@@ -1,28 +1,40 @@
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import * as React from 'react';
import { BaseOpenTelemetryComponent } from '../../src';

export default class AllLifecycles extends BaseOpenTelemetryComponent {
constructor(props: Readonly<any>){
super(props);
}
constructor(props: Readonly<any>) {
super(props);
}

override componentDidMount() {}

componentDidMount(){
}
override componentDidUpdate(prevProps: any) {}

componentDidUpdate(prevProps: any){
}
override shouldComponentUpdate(nextProps: any, nextState: any) {
return true;
}

shouldComponentUpdate(nextProps: any, nextState: any){
return true;
}

getSnapshotBeforeUpdate(prevProps: any, prevState: any){
return null;
}
override getSnapshotBeforeUpdate(prevProps: any, prevState: any) {
return null;
}

render() {
return(
<div></div>
);
}
override render() {
return <div></div>;
}
}

0 comments on commit 1540bd0

Please sign in to comment.