Skip to content

Commit

Permalink
Merge branch 'open-telemetry:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
nozik committed May 14, 2021
2 parents 7ec18cd + aec35d8 commit 9231d12
Show file tree
Hide file tree
Showing 52 changed files with 311 additions and 292 deletions.
6 changes: 4 additions & 2 deletions metapackages/auto-instrumentations-web/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ import { XMLHttpRequestInstrumentation } from '@opentelemetry/instrumentation-xm
const InstrumentationMap = {
'@opentelemetry/instrumentation-document-load': DocumentLoadInstrumentation,
'@opentelemetry/instrumentation-fetch': FetchInstrumentation,
'@opentelemetry/instrumentation-user-interaction': UserInteractionInstrumentation,
'@opentelemetry/instrumentation-xml-http-request': XMLHttpRequestInstrumentation,
'@opentelemetry/instrumentation-user-interaction':
UserInteractionInstrumentation,
'@opentelemetry/instrumentation-xml-http-request':
XMLHttpRequestInstrumentation,
};

// Config types inferred automatically from the first argument of the constructor
Expand Down
3 changes: 2 additions & 1 deletion metapackages/auto-instrumentations-web/test/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ describe('utils', () => {
instr.instrumentationName ===
'@opentelemetry/instrumentation-xml-http-request'
) as any;
const config = instrumentation._config as XMLHttpRequestInstrumentationConfig;
const config =
instrumentation._config as XMLHttpRequestInstrumentationConfig;

assert.strictEqual(config.clearTimingResources, clearTimingResources);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ import {
SpanStatusCode,
TracerProvider,
} from '@opentelemetry/api';
import { CLOUD_RESOURCE } from '@opentelemetry/resources';
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
import {
SemanticAttributes,
ResourceAttributes,
} from '@opentelemetry/semantic-conventions';

import { Callback, Context, Handler } from 'aws-lambda';

Expand Down Expand Up @@ -121,10 +123,11 @@ export class AwsLambdaInstrumentation extends InstrumentationBase {
kind: SpanKind.SERVER,
attributes: {
[SemanticAttributes.FAAS_EXECUTION]: context.awsRequestId,
'faas.id': context.invokedFunctionArn,
[CLOUD_RESOURCE.ACCOUNT_ID]: AwsLambdaInstrumentation._extractAccountId(
context.invokedFunctionArn
),
[ResourceAttributes.FAAS_ID]: context.invokedFunctionArn,
[ResourceAttributes.CLOUD_ACCOUNT_ID]:
AwsLambdaInstrumentation._extractAccountId(
context.invokedFunctionArn
),
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ describe('Utility', () => {

it('should throw if type is unknown', () => {
try {
utils.satisfiesPattern(
'google.com',
(true as unknown) as IgnoreMatcher
);
utils.satisfiesPattern('google.com', true as unknown as IgnoreMatcher);
assert.fail();
} catch (error) {
assert.strictEqual(error instanceof TypeError, true);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* 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.
*/
export enum AttributeNames {
EXPRESS_TYPE = 'express.type',
EXPRESS_NAME = 'express.name',
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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.
*/
export enum ExpressLayerType {
ROUTER = 'router',
MIDDLEWARE = 'middleware',
REQUEST_HANDLER = 'request_handler',
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ import * as express from 'express';
import {
ExpressLayer,
ExpressRouter,
CustomAttributeNames,
PatchedRequest,
_LAYERS_STORE_PROPERTY,
ExpressInstrumentationConfig,
ExpressLayerType,
ExpressInstrumentationSpan,
} from './types';
import { ExpressLayerType } from './enums/ExpressLayerType';
import { AttributeNames } from './enums/AttributeNames';
import { getLayerMetadata, storeLayerPath, isLayerIgnored } from './utils';
import { VERSION } from './version';
import {
Expand Down Expand Up @@ -61,7 +61,7 @@ export class ExpressInstrumentation extends InstrumentationBase<
['^4.0.0'],
(moduleExports, moduleVersion) => {
diag.debug(`Applying patch for express@${moduleVersion}`);
const routerProto = (moduleExports.Router as unknown) as express.Router;
const routerProto = moduleExports.Router as unknown as express.Router;
// patch express.Router.route
if (isWrapped(routerProto.route)) {
this._unwrap(routerProto, 'route');
Expand Down Expand Up @@ -187,13 +187,13 @@ export class ExpressInstrumentation extends InstrumentationBase<
};
const metadata = getLayerMetadata(layer, layerPath);
const type = metadata.attributes[
CustomAttributeNames.EXPRESS_TYPE
AttributeNames.EXPRESS_TYPE
] as ExpressLayerType;

// Rename the root http span in case we haven't done it already
// once we reach the request handler
if (
metadata.attributes[CustomAttributeNames.EXPRESS_TYPE] ===
metadata.attributes[AttributeNames.EXPRESS_TYPE] ===
ExpressLayerType.REQUEST_HANDLER
) {
const parent = getSpan(
Expand Down Expand Up @@ -226,7 +226,7 @@ export class ExpressInstrumentation extends InstrumentationBase<
// If we found anything that isnt a middleware, there no point of measuring
// their time since they dont have callback.
if (
metadata.attributes[CustomAttributeNames.EXPRESS_TYPE] !==
metadata.attributes[AttributeNames.EXPRESS_TYPE] !==
ExpressLayerType.MIDDLEWARE
) {
span.end(startTime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
*/

export * from './express';
export { ExpressInstrumentationConfig, ExpressLayerType } from './types';
export { ExpressLayerType } from './enums/ExpressLayerType';
export { ExpressInstrumentationConfig } from './types';
12 changes: 1 addition & 11 deletions plugins/node/opentelemetry-instrumentation-express/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { kLayerPatched } from './express';
import { Request } from 'express';
import { SpanAttributes, Span } from '@opentelemetry/api';
import { InstrumentationConfig } from '@opentelemetry/instrumentation';
import { ExpressLayerType } from './enums/ExpressLayerType';

/**
* This const define where on the `request` object the Instrumentation will mount the
Expand Down Expand Up @@ -67,17 +68,6 @@ export type LayerMetadata = {
name: string;
};

export enum CustomAttributeNames {
EXPRESS_TYPE = 'express.type',
EXPRESS_NAME = 'express.name',
}

export enum ExpressLayerType {
ROUTER = 'router',
MIDDLEWARE = 'middleware',
REQUEST_HANDLER = 'request_handler',
}

export type IgnoreMatcher = string | RegExp | ((name: string) => boolean);

/**
Expand Down
16 changes: 8 additions & 8 deletions plugins/node/opentelemetry-instrumentation-express/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
import { SpanAttributes } from '@opentelemetry/api';
import {
ExpressLayer,
CustomAttributeNames,
PatchedRequest,
_LAYERS_STORE_PROPERTY,
ExpressLayerType,
IgnoreMatcher,
ExpressInstrumentationConfig,
} from './types';
import { ExpressLayerType } from './enums/ExpressLayerType';
import { AttributeNames } from './enums/AttributeNames';

/**
* Store layers path in the request to be able to construct route later
Expand Down Expand Up @@ -56,24 +56,24 @@ export const getLayerMetadata = (
if (layer.name === 'router') {
return {
attributes: {
[CustomAttributeNames.EXPRESS_NAME]: layerPath,
[CustomAttributeNames.EXPRESS_TYPE]: ExpressLayerType.ROUTER,
[AttributeNames.EXPRESS_NAME]: layerPath,
[AttributeNames.EXPRESS_TYPE]: ExpressLayerType.ROUTER,
},
name: `router - ${layerPath}`,
};
} else if (layer.name === 'bound dispatch') {
return {
attributes: {
[CustomAttributeNames.EXPRESS_NAME]: layerPath ?? 'request handler',
[CustomAttributeNames.EXPRESS_TYPE]: ExpressLayerType.REQUEST_HANDLER,
[AttributeNames.EXPRESS_NAME]: layerPath ?? 'request handler',
[AttributeNames.EXPRESS_TYPE]: ExpressLayerType.REQUEST_HANDLER,
},
name: `request handler${layer.path ? ` - ${layerPath}` : ''}`,
};
} else {
return {
attributes: {
[CustomAttributeNames.EXPRESS_NAME]: layer.name,
[CustomAttributeNames.EXPRESS_TYPE]: ExpressLayerType.MIDDLEWARE,
[AttributeNames.EXPRESS_NAME]: layer.name,
[AttributeNames.EXPRESS_TYPE]: ExpressLayerType.MIDDLEWARE,
},
name: `middleware - ${layer.name}`,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@ import {
} from '@opentelemetry/tracing';
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
import * as assert from 'assert';
import {
CustomAttributeNames,
ExpressInstrumentationSpan,
ExpressLayerType,
} from '../src/types';
import { ExpressInstrumentationSpan } from '../src/types';
import { ExpressLayerType } from '../src/enums/ExpressLayerType';
import { AttributeNames } from '../src/enums/AttributeNames';
import { ExpressInstrumentation } from '../src';

const instrumentation = new ExpressInstrumentation({
Expand Down Expand Up @@ -115,7 +113,7 @@ describe('ExpressInstrumentation', () => {
.getFinishedSpans()
.filter(
span =>
span.attributes[CustomAttributeNames.EXPRESS_TYPE] ===
span.attributes[AttributeNames.EXPRESS_TYPE] ===
ExpressLayerType.MIDDLEWARE
).length,
0
Expand Down Expand Up @@ -164,7 +162,7 @@ describe('ExpressInstrumentation', () => {
);

assert.strictEqual(
requestHandlerSpan?.attributes[CustomAttributeNames.EXPRESS_TYPE],
requestHandlerSpan?.attributes[AttributeNames.EXPRESS_TYPE],
'request_handler'
);
const exportedRootSpan = spans.find(span => span.name === 'GET /mw');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import {
SimpleSpanProcessor,
} from '@opentelemetry/tracing';
import * as assert from 'assert';
import { CustomAttributeNames, ExpressInstrumentationSpan } from '../src/types';
import { ExpressInstrumentationSpan } from '../src/types';
import { AttributeNames } from '../src/enums/AttributeNames';
import { ExpressInstrumentation } from '../src';
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';

Expand Down Expand Up @@ -168,7 +169,7 @@ describe('ExpressInstrumentation', () => {
'/toto/:id'
);
assert.strictEqual(
requestHandlerSpan?.attributes[CustomAttributeNames.EXPRESS_TYPE],
requestHandlerSpan?.attributes[AttributeNames.EXPRESS_TYPE],
'request_handler'
);
const exportedRootSpan = memoryExporter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import {
SimpleSpanProcessor,
} from '@opentelemetry/tracing';
import * as assert from 'assert';
import { CustomAttributeNames, ExpressInstrumentationSpan } from '../src/types';
import { ExpressInstrumentationSpan } from '../src/types';
import { AttributeNames } from '../src/enums/AttributeNames';
import { ExpressInstrumentation, ExpressLayerType } from '../src';

const instrumentation = new ExpressInstrumentation({
Expand Down Expand Up @@ -120,11 +121,11 @@ describe('ExpressInstrumentation', () => {
.getFinishedSpans()
.filter(
span =>
span.attributes[CustomAttributeNames.EXPRESS_TYPE] ===
span.attributes[AttributeNames.EXPRESS_TYPE] ===
ExpressLayerType.MIDDLEWARE ||
span.attributes[CustomAttributeNames.EXPRESS_TYPE] ===
span.attributes[AttributeNames.EXPRESS_TYPE] ===
ExpressLayerType.ROUTER ||
span.attributes[CustomAttributeNames.EXPRESS_TYPE] ===
span.attributes[AttributeNames.EXPRESS_TYPE] ===
ExpressLayerType.REQUEST_HANDLER
).length,
0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@

import * as utils from '../src/utils';
import * as assert from 'assert';
import {
ExpressLayerType,
ExpressInstrumentationConfig,
ExpressLayer,
CustomAttributeNames,
} from '../src/types';
import { ExpressInstrumentationConfig, ExpressLayer } from '../src/types';
import { ExpressLayerType } from '../src/enums/ExpressLayerType';
import { AttributeNames } from '../src/enums/AttributeNames';

describe('Utils', () => {
describe('isLayerIgnored()', () => {
Expand Down Expand Up @@ -103,8 +100,8 @@ describe('Utils', () => {
),
{
attributes: {
[CustomAttributeNames.EXPRESS_NAME]: '/test',
[CustomAttributeNames.EXPRESS_TYPE]: 'router',
[AttributeNames.EXPRESS_NAME]: '/test',
[AttributeNames.EXPRESS_TYPE]: 'router',
},
name: 'router - /test',
}
Expand All @@ -121,8 +118,8 @@ describe('Utils', () => {
),
{
attributes: {
[CustomAttributeNames.EXPRESS_NAME]: '/:id',
[CustomAttributeNames.EXPRESS_TYPE]: 'request_handler',
[AttributeNames.EXPRESS_NAME]: '/:id',
[AttributeNames.EXPRESS_TYPE]: 'request_handler',
},
name: 'request handler',
}
Expand All @@ -136,8 +133,8 @@ describe('Utils', () => {
} as ExpressLayer),
{
attributes: {
[CustomAttributeNames.EXPRESS_NAME]: 'bodyParser',
[CustomAttributeNames.EXPRESS_TYPE]: 'middleware',
[AttributeNames.EXPRESS_NAME]: 'bodyParser',
[AttributeNames.EXPRESS_TYPE]: 'middleware',
},
name: 'middleware - bodyParser',
}
Expand Down
11 changes: 0 additions & 11 deletions plugins/node/opentelemetry-instrumentation-graphql/src/enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,6 @@ export enum TokenKind {
COMMENT = 'Comment',
}

export enum SpanAttributes {
COMPONENT = 'graphql',
SOURCE = 'graphql.source',
FIELD_NAME = 'graphql.field.name',
FIELD_PATH = 'graphql.field.path',
FIELD_TYPE = 'graphql.field.type',
OPERATION = 'graphql.operation.name',
VARIABLES = 'graphql.variables.',
ERROR_VALIDATION_NAME = 'graphql.validation.error',
}

export enum SpanNames {
EXECUTE = 'graphql.execute',
PARSE = 'graphql.parse',
Expand Down
Loading

0 comments on commit 9231d12

Please sign in to comment.