Skip to content

Commit

Permalink
[ZARS-669][ADD] update opentelemetry packages (#28)
Browse files Browse the repository at this point in the history
* update opentelemetry dependencies

* [ZARS-669] fix types

* [ZARS-669] fix lockfile version mismatch

* [ZARS-699][ADD] refactoring

* [ZARS-669][ADD] refactor deprecations

* [ZARS-669][ADD] replace telemetry mongoose package

* [ZARS-669][ADD] replace constant with string

* [ZARS-669][ADD] remove deprecations
  • Loading branch information
af-egr authored Dec 4, 2024
1 parent 6fa7cef commit d45d43a
Show file tree
Hide file tree
Showing 7 changed files with 228 additions and 261 deletions.
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@
"@nestjs/schedule": "^2.2.2",
"@nestjs/serve-static": "^3.0.1",
"@nestjs/swagger": "^6.3.0",
"@opentelemetry/api": "^1.8.0",
"@opentelemetry/exporter-trace-otlp-proto": "^0.51.1",
"@opentelemetry/instrumentation-http": "^0.51.1",
"@opentelemetry/instrumentation-nestjs-core": "^0.37.1",
"@opentelemetry/sdk-trace-base": "^1.24.1",
"@opentelemetry/sdk-trace-node": "^1.24.1",
"@opentelemetry/semantic-conventions": "^1.24.1",
"@opentelemetry/api": "^1.9.0",
"@opentelemetry/exporter-trace-otlp-proto": "^0.55.0",
"@opentelemetry/instrumentation-http": "^0.55.0",
"@opentelemetry/instrumentation-mongoose": "^0.44.0",
"@opentelemetry/instrumentation-nestjs-core": "^0.42.0",
"@opentelemetry/sdk-trace-base": "^1.28.0",
"@opentelemetry/sdk-trace-node": "^1.28.0",
"@opentelemetry/semantic-conventions": "^1.28.0",
"@sendinblue/client": "^3.3.1",
"axios": "^1.7.2",
"cache-manager": "^5.5.3",
Expand All @@ -52,11 +53,10 @@
"jwks-rsa": "^3.1.0",
"minio": "^7.1.1",
"mongoose": "^7.6.9",
"opentelemetry-instrumentation-mongoose": "^0.34.0",
"passport": "^0.6.0",
"passport-jwt": "^4.0.1",
"pdf-lib": "^1.17.1",
"reflect-metadata": "^0.1.13",
"reflect-metadata": "^0.1.14",
"rimraf": "^5.0.7",
"rxjs": "^7.8.1",
"uuid": "^9.0.1"
Expand Down
8 changes: 4 additions & 4 deletions src/modules/feasibility/feasibility.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ export class FeasibilityClient {
kind: SpanKind.CLIENT,
root: true,
attributes: {
[SemanticAttributes.HTTP_METHOD]: 'POST',
[SemanticAttributes.HTTP_HOST]: this.keycloakHost,
[SemanticAttributes.HTTP_TARGET]: this.tokenEndpoint,
[SemanticAttributes.HTTP_URL]: this.tokenEndpoint,
['http.method']: 'POST',
['http.host']: this.keycloakHost,
['http.target']: this.tokenEndpoint,
['http.url']: this.tokenEndpoint,
['feasibilityClient.keycloakClientId']: this.clientId,
['feasibilityClient.keycloakClientSecret']:
'*******' + this.clientSecret.slice(this.clientSecret.length - 2, this.clientSecret.length),
Expand Down
4 changes: 2 additions & 2 deletions src/modules/proposal/utils/is-done-overview.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ const findIsDone = (obj: Proposal, path?: string) => {
.filter((item) => item.length)
.flat(10);
acc.push(...items);
} else if (isObject(obj[key]) && typeof obj[key].getMonth !== 'function') {
acc.push(...findIsDone(obj[key], pathToValue));
} else if (isObject<any>(obj[key]) && typeof obj[key].getMonth !== 'function') {
acc.push(...findIsDone(obj[key] as Proposal, pathToValue));
}

return acc;
Expand Down
2 changes: 1 addition & 1 deletion src/modules/proposal/utils/merge-proposal.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const mergeDeep = (target, ...sources) => {

if (isObject(target) && isObject(source)) {
for (const key in source) {
if (isObject(source[key]) && typeof source[key].getMonth !== 'function') {
if (isObject<any>(source[key]) && typeof source[key].getMonth !== 'function') {
if (!target[key]) Object.assign(target, { [key]: {} });
mergeDeep(target[key], source[key]);
} else {
Expand Down
9 changes: 4 additions & 5 deletions src/modules/user/keycloak.client.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { SpanKind, SpanStatusCode, context, trace } from '@opentelemetry/api';
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
import axios, { AxiosError, AxiosInstance, AxiosResponse, InternalAxiosRequestConfig } from 'axios';
import { ITokenResult } from '../../shared/types/token-result.interface';
@Injectable()
Expand Down Expand Up @@ -45,10 +44,10 @@ export class KeycloakClient {
kind: SpanKind.CLIENT,
root: true,
attributes: {
[SemanticAttributes.HTTP_METHOD]: 'POST',
[SemanticAttributes.HTTP_HOST]: this.host,
[SemanticAttributes.HTTP_TARGET]: this.tokenEndpoint,
[SemanticAttributes.HTTP_URL]: this.tokenEndpoint,
['http.method']: 'POST',
['http.host']: this.host,
['http.target']: this.tokenEndpoint,
['http.url']: this.tokenEndpoint,
['keycloakClient.keycloakClientId']: this.clientId,
['keycloakClient.keycloakClientSecret']:
'*******' + this.clientSecret.slice(this.clientSecret.length - 2, this.clientSecret.length),
Expand Down
27 changes: 16 additions & 11 deletions src/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import { NestInstrumentation } from '@opentelemetry/instrumentation-nestjs-core'
import { Resource } from '@opentelemetry/resources';
import { BatchSpanProcessor } from '@opentelemetry/sdk-trace-base';
import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import { ATTR_SERVICE_NAME, ATTR_SERVICE_VERSION } from '@opentelemetry/semantic-conventions';
import { IncomingMessage } from 'http';
import { MongooseInstrumentation, SerializerPayload } from 'opentelemetry-instrumentation-mongoose';
import { IRequestUser } from './shared/types/request-user.interface';
import { MongooseInstrumentation, SerializerPayload } from '@opentelemetry/instrumentation-mongoose';

export const configureTelemetry = (config: {
connectionString: string;
Expand All @@ -22,21 +22,26 @@ export const configureTelemetry = (config: {
if (config.enableTelemetry) {
const resource = Resource.default().merge(
new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: 'FDPG-API_' + config.env,
[SemanticResourceAttributes.SERVICE_VERSION]: config.softwareVersion,
[SemanticResourceAttributes.DEPLOYMENT_ENVIRONMENT]: config.env,
[ATTR_SERVICE_NAME]: 'FDPG-API_' + config.env,
[ATTR_SERVICE_VERSION]: config.softwareVersion,
['deployment.environment']: config.env,
application: 'FDPG-API_' + config.env,
}),
);

const provider = new NodeTracerProvider({ resource });
const spanProcessors = [
new BatchSpanProcessor(
new OTLPTraceExporter({
url: config.connectionString,
}),
),
];

const exporter = new OTLPTraceExporter({
url: config.connectionString,
const provider = new NodeTracerProvider({
resource,
spanProcessors,
});

provider.addSpanProcessor(new BatchSpanProcessor(exporter));

provider.register({
propagator: new W3CTraceContextPropagator(),
});
Expand All @@ -57,7 +62,7 @@ export const configureTelemetry = (config: {
const panelQuery = url.searchParams.get('panelQuery');
const user = (request as any).user as IRequestUser;
span.setAttributes({
[SemanticResourceAttributes.SERVICE_VERSION]: config.softwareVersion,
[ATTR_SERVICE_NAME]: config.softwareVersion,
['request.method']: request.method,
['request.user-agent']: request.headers['user-agent'],
['request.referer']: request.headers['referer'],
Expand Down
Loading

0 comments on commit d45d43a

Please sign in to comment.