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

feat: add semconv generator for semantic-conventions-package #2083

Merged
merged 17 commits into from
Apr 10, 2021
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
c131413
feat: add semconv generator for `semantic-conventions`-package
tapico-weyert Apr 8, 2021
4724305
feat: update `semantic-conventations`-package by generating using new…
tapico-weyert Apr 8, 2021
310d124
fix: update packages to use the new `SemanticAttribute`-class
tapico-weyert Apr 8, 2021
5b40934
fix: improve the `semconv`-template to better match eslint prettier r…
tapico-weyert Apr 8, 2021
3e9f64e
chore: run `lint:fix`-task after generating source files
tapico-weyert Apr 8, 2021
3302972
chore: move argument to its own line in `generate.sh`
tapico-weyert Apr 8, 2021
9b889ef
fix: ensure we generate against v1.1.0 of the spec
tapico-weyert Apr 8, 2021
55d2c9b
fix: removed the out of spec semantic conventions from package
tapico-weyert Apr 8, 2021
3ff5b47
chore: merge branch 'main' into chore-otel-add-semconv-generator
tapico-weyert Apr 8, 2021
a8b4115
style: ran `npm run lint:fix` on the code base
tapico-weyert Apr 8, 2021
c2fb34a
fix: use `RPC_GRPC_STATUS_CODE` from `semantic-convention` that a cus…
tapico-weyert Apr 8, 2021
4b16cff
test: fix Span test to ensure attribute value is a string
tapico-weyert Apr 8, 2021
79c9720
chore: merge branch 'upstream-main' into chore-otel-add-semconv-gener…
tapico-weyert Apr 9, 2021
8eda347
chore: attempt to correct fix failed merge
tapico-weyert Apr 9, 2021
5b45d5b
fix: remove unwanted `@deprecated`-attribute in semconv template file
tapico-weyert Apr 10, 2021
50ce031
fix: don't fetch the whole otel specification repo
tapico-weyert Apr 10, 2021
628bb71
Merge branch 'main' into chore-otel-add-semconv-generator
weyert Apr 10, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@
*/
export enum AttributeNames {
COMPONENT = 'component',
HTTP_ERROR_NAME = 'http.error_name',
HTTP_STATUS_TEXT = 'http.status_text',
}
16 changes: 8 additions & 8 deletions packages/opentelemetry-instrumentation-fetch/src/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
import * as core from '@opentelemetry/core';
import * as web from '@opentelemetry/web';
import { AttributeNames } from './enums/AttributeNames';
import { HttpAttribute } from '@opentelemetry/semantic-conventions';
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
import { FetchError, FetchResponse, SpanData } from './types';
import { VERSION } from './version';

Expand Down Expand Up @@ -121,16 +121,16 @@ export class FetchInstrumentation extends InstrumentationBase<
response: FetchResponse
): void {
const parsedUrl = web.parseUrl(response.url);
span.setAttribute(HttpAttribute.HTTP_STATUS_CODE, response.status);
span.setAttribute(SemanticAttributes.HTTP_STATUS_CODE, response.status);
if (response.statusText != null) {
span.setAttribute(HttpAttribute.HTTP_STATUS_TEXT, response.statusText);
span.setAttribute(AttributeNames.HTTP_STATUS_TEXT, response.statusText);
}
span.setAttribute(HttpAttribute.HTTP_HOST, parsedUrl.host);
span.setAttribute(SemanticAttributes.HTTP_HOST, parsedUrl.host);
span.setAttribute(
HttpAttribute.HTTP_SCHEME,
SemanticAttributes.HTTP_SCHEME,
parsedUrl.protocol.replace(':', '')
);
span.setAttribute(HttpAttribute.HTTP_USER_AGENT, navigator.userAgent);
span.setAttribute(SemanticAttributes.HTTP_USER_AGENT, navigator.userAgent);
}

/**
Expand Down Expand Up @@ -196,8 +196,8 @@ export class FetchInstrumentation extends InstrumentationBase<
kind: api.SpanKind.CLIENT,
attributes: {
[AttributeNames.COMPONENT]: this.moduleName,
[HttpAttribute.HTTP_METHOD]: method,
[HttpAttribute.HTTP_URL]: url,
[SemanticAttributes.HTTP_METHOD]: method,
[SemanticAttributes.HTTP_URL]: url,
},
});
}
Expand Down
20 changes: 10 additions & 10 deletions packages/opentelemetry-instrumentation-fetch/test/fetch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import * as assert from 'assert';
import * as sinon from 'sinon';
import { FetchInstrumentation, FetchInstrumentationConfig } from '../src';
import { AttributeNames } from '../src/enums/AttributeNames';
import { HttpAttribute } from '@opentelemetry/semantic-conventions';
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';

class DummySpanExporter implements tracing.SpanExporter {
export(spans: any) {}
Expand Down Expand Up @@ -335,37 +335,37 @@ describe('fetch', () => {
assert.strictEqual(
attributes[keys[1]],
'GET',
`attributes ${HttpAttribute.HTTP_METHOD} is wrong`
`attributes ${SemanticAttributes.HTTP_METHOD} is wrong`
);
assert.strictEqual(
attributes[keys[2]],
url,
`attributes ${HttpAttribute.HTTP_URL} is wrong`
`attributes ${SemanticAttributes.HTTP_URL} is wrong`
);
assert.strictEqual(
attributes[keys[3]],
200,
`attributes ${HttpAttribute.HTTP_STATUS_CODE} is wrong`
`attributes ${SemanticAttributes.HTTP_STATUS_CODE} is wrong`
);
assert.ok(
attributes[keys[4]] === 'OK' || attributes[keys[4]] === '',
`attributes ${HttpAttribute.HTTP_STATUS_TEXT} is wrong`
`attributes ${AttributeNames.HTTP_STATUS_TEXT} is wrong`
);
assert.ok(
(attributes[keys[5]] as string).indexOf('localhost') === 0,
`attributes ${HttpAttribute.HTTP_HOST} is wrong`
`attributes ${SemanticAttributes.HTTP_HOST} is wrong`
);
assert.ok(
attributes[keys[6]] === 'http' || attributes[keys[6]] === 'https',
`attributes ${HttpAttribute.HTTP_SCHEME} is wrong`
`attributes ${SemanticAttributes.HTTP_SCHEME} is wrong`
);
assert.ok(
attributes[keys[7]] !== '',
`attributes ${HttpAttribute.HTTP_USER_AGENT} is not defined`
`attributes ${SemanticAttributes.HTTP_USER_AGENT} is not defined`
);
assert.ok(
(attributes[keys[8]] as number) > 0,
`attributes ${HttpAttribute.HTTP_RESPONSE_CONTENT_LENGTH} is <= 0`
`attributes ${SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH} is <= 0`
);

assert.strictEqual(keys.length, 9, 'number of attributes is wrong');
Expand Down Expand Up @@ -764,7 +764,7 @@ describe('fetch', () => {
assert.strictEqual(
attributes[keys[3]],
200,
`Missing basic attribute ${HttpAttribute.HTTP_STATUS_CODE}`
`Missing basic attribute ${SemanticAttributes.HTTP_STATUS_CODE}`
);
});
});
Expand Down
25 changes: 25 additions & 0 deletions packages/opentelemetry-instrumentation-grpc/src/enums.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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.
*/

/**
* https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/http.md
*/
export enum AttributeNames {
GRPC_KIND = 'grpc.kind', // SERVER or CLIENT
GRPC_METHOD = 'grpc.method',
GRPC_ERROR_NAME = 'grpc.error_name',
GRPC_ERROR_MESSAGE = 'grpc.error_message',
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
propagation,
context,
} from '@opentelemetry/api';
import { RpcAttribute } from '@opentelemetry/semantic-conventions';
import type * as grpcJs from '@grpc/grpc-js';
import {
_grpcStatusCodeToSpanStatus,
Expand All @@ -33,6 +32,8 @@ import {
} from '../utils';
import { CALL_SPAN_ENDED } from './serverUtils';
import { EventEmitter } from 'events';
import { AttributeNames } from '../enums';
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';

/**
* Parse a package method list and return a list of methods to patch
Expand Down Expand Up @@ -89,16 +90,19 @@ export function makeGrpcClientRemoteCall(
if (err) {
if (err.code) {
span.setStatus(_grpcStatusCodeToSpanStatus(err.code));
span.setAttribute(RpcAttribute.GRPC_STATUS_CODE, err.code.toString());
span.setAttribute(
SemanticAttributes.RPC_GRPC_STATUS_CODE,
err.code.toString()
);
}
span.setAttributes({
[RpcAttribute.GRPC_ERROR_NAME]: err.name,
[RpcAttribute.GRPC_ERROR_MESSAGE]: err.message,
[AttributeNames.GRPC_ERROR_NAME]: err.name,
[AttributeNames.GRPC_ERROR_MESSAGE]: err.message,
});
} else {
span.setStatus({ code: SpanStatusCode.UNSET });
span.setAttribute(
RpcAttribute.GRPC_STATUS_CODE,
SemanticAttributes.RPC_GRPC_STATUS_CODE,
SpanStatusCode.UNSET.toString()
);
}
Expand All @@ -124,8 +128,8 @@ export function makeGrpcClientRemoteCall(
}

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

setSpanContext(metadata);
Expand Down Expand Up @@ -154,8 +158,8 @@ export function makeGrpcClientRemoteCall(
message: err.message,
});
span.setAttributes({
[RpcAttribute.GRPC_ERROR_NAME]: err.name,
[RpcAttribute.GRPC_ERROR_MESSAGE]: err.message,
[AttributeNames.GRPC_ERROR_NAME]: err.name,
[AttributeNames.GRPC_ERROR_MESSAGE]: err.message,
});

endSpan();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import {
setSpan,
diag,
} from '@opentelemetry/api';
import { RpcAttribute } from '@opentelemetry/semantic-conventions';
import {
shouldNotTraceServerCall,
handleServerFunction,
Expand All @@ -54,6 +53,7 @@ import {
getMetadata,
} from './clientUtils';
import { EventEmitter } from 'events';
import { AttributeNames } from '../enums';

export class GrpcJsInstrumentation extends InstrumentationBase {
constructor(
Expand Down Expand Up @@ -197,7 +197,7 @@ export class GrpcJsInstrumentation extends InstrumentationBase {
const span = instrumentation.tracer
.startSpan(spanName, spanOptions)
.setAttributes({
[RpcAttribute.GRPC_KIND]: spanOptions.kind,
[AttributeNames.GRPC_KIND]: spanOptions.kind,
});

context.with(setSpan(context.active(), span), () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
*/

import { context, Span, SpanStatusCode } from '@opentelemetry/api';
import { RpcAttribute } from '@opentelemetry/semantic-conventions';
import type * as grpcJs from '@grpc/grpc-js';
import type {
ServerCallWithMeta,
Expand All @@ -34,6 +33,8 @@ import {
_methodIsIgnored,
} from '../utils';
import { IgnoreMatcher } from '../types';
import { AttributeNames } from '../enums';
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';

export const CALL_SPAN_ENDED = Symbol('opentelemetry call span ended');

Expand Down Expand Up @@ -70,7 +71,7 @@ function serverStreamAndBidiHandler<RequestType, ResponseType>(
code: SpanStatusCode.UNSET,
});
span.setAttribute(
RpcAttribute.GRPC_STATUS_CODE,
SemanticAttributes.RPC_GRPC_STATUS_CODE,
SpanStatusCode.OK.toString()
);

Expand All @@ -90,8 +91,8 @@ function serverStreamAndBidiHandler<RequestType, ResponseType>(
message: err.message,
});
span.setAttributes({
[RpcAttribute.GRPC_ERROR_NAME]: err.name,
[RpcAttribute.GRPC_ERROR_MESSAGE]: err.message,
[AttributeNames.GRPC_ERROR_NAME]: err.name,
[AttributeNames.GRPC_ERROR_MESSAGE]: err.message,
});
endSpan();
});
Expand Down Expand Up @@ -121,16 +122,19 @@ function clientStreamAndUnaryHandler<RequestType, ResponseType>(
code: _grpcStatusCodeToOpenTelemetryStatusCode(err.code),
message: err.message,
});
span.setAttribute(RpcAttribute.GRPC_STATUS_CODE, err.code.toString());
span.setAttribute(
SemanticAttributes.RPC_GRPC_STATUS_CODE,
err.code.toString()
);
}
span.setAttributes({
[RpcAttribute.GRPC_ERROR_NAME]: err.name,
[RpcAttribute.GRPC_ERROR_MESSAGE]: err.message,
[AttributeNames.GRPC_ERROR_NAME]: err.name,
[AttributeNames.GRPC_ERROR_MESSAGE]: err.message,
});
} else {
span.setStatus({ code: SpanStatusCode.UNSET });
span.setAttribute(
RpcAttribute.GRPC_STATUS_CODE,
SemanticAttributes.RPC_GRPC_STATUS_CODE,
SpanStatusCode.OK.toString()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import type * as grpcTypes from 'grpc';
import type * as events from 'events';
import { SendUnaryDataCallback, GrpcClientFunc } from './types';
import { RpcAttribute } from '@opentelemetry/semantic-conventions';
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
import {
context,
Span,
Expand All @@ -31,6 +31,7 @@ import {
_grpcStatusCodeToOpenTelemetryStatusCode,
findIndex,
} from '../utils';
import { AttributeNames } from '../enums';

/**
* This method handles the client remote call
Expand All @@ -55,16 +56,19 @@ export const makeGrpcClientRemoteCall = function (
if (err) {
if (err.code) {
span.setStatus(_grpcStatusCodeToSpanStatus(err.code));
span.setAttribute(RpcAttribute.GRPC_STATUS_CODE, err.code.toString());
span.setAttribute(
SemanticAttributes.RPC_GRPC_STATUS_CODE,
err.code.toString()
);
}
span.setAttributes({
[RpcAttribute.GRPC_ERROR_NAME]: err.name,
[RpcAttribute.GRPC_ERROR_MESSAGE]: err.message,
[AttributeNames.GRPC_ERROR_NAME]: err.name,
[AttributeNames.GRPC_ERROR_MESSAGE]: err.message,
});
} else {
span.setStatus({ code: SpanStatusCode.UNSET });
span.setAttribute(
RpcAttribute.GRPC_STATUS_CODE,
SemanticAttributes.RPC_GRPC_STATUS_CODE,
grpcClient.status.OK.toString()
);
}
Expand Down Expand Up @@ -96,8 +100,8 @@ export const makeGrpcClientRemoteCall = function (

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

setSpanContext(metadata);
Expand All @@ -123,8 +127,8 @@ export const makeGrpcClientRemoteCall = function (
message: err.message,
});
span.setAttributes({
[RpcAttribute.GRPC_ERROR_NAME]: err.name,
[RpcAttribute.GRPC_ERROR_MESSAGE]: err.message,
[AttributeNames.GRPC_ERROR_NAME]: err.name,
[AttributeNames.GRPC_ERROR_MESSAGE]: err.message,
});
endSpan();
}
Expand All @@ -135,7 +139,7 @@ export const makeGrpcClientRemoteCall = function (
(status: SpanStatus) => {
span.setStatus({ code: SpanStatusCode.UNSET });
span.setAttribute(
RpcAttribute.GRPC_STATUS_CODE,
SemanticAttributes.RPC_GRPC_STATUS_CODE,
status.code.toString()
);
endSpan();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import {
GrpcClientFunc,
} from './types';
import { GrpcInstrumentationConfig } from '../types';
import { RpcAttribute } from '@opentelemetry/semantic-conventions';
import {
context,
propagation,
Expand All @@ -45,6 +44,7 @@ import {
} from './serverUtils';
import { makeGrpcClientRemoteCall, getMetadata } from './clientUtils';
import { _methodIsIgnored } from '../utils';
import { AttributeNames } from '../enums';

/**
* Holding reference to grpc module here to access constant of grpc modules
Expand Down Expand Up @@ -205,7 +205,7 @@ export class GrpcNativeInstrumentation extends InstrumentationBase<
const span = instrumentation.tracer
.startSpan(spanName, spanOptions)
.setAttributes({
[RpcAttribute.GRPC_KIND]: spanOptions.kind,
[AttributeNames.GRPC_KIND]: spanOptions.kind,
});

context.with(setSpan(context.active(), span), () => {
Expand Down
Loading