Skip to content

Commit

Permalink
feat: run lint
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-lima-gaivota committed Aug 29, 2023
1 parent f52dbee commit 2efa10e
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 54 deletions.
11 changes: 5 additions & 6 deletions src/utils/interceptors/http-tracing.interceptor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CallHandler, ExecutionContext, Injectable, NestInterceptor } from '@nestjs/common';
import { Context } from '@opentelemetry/api';
import axios, { AxiosInstance, AxiosRequestConfig } from 'axios';
import axiosBetterStacktrace from 'axios-better-stacktrace';
import { initTracer, JaegerTracer, TracingConfig, TracingOptions } from 'jaeger-client';
Expand All @@ -12,7 +13,6 @@ import { ILoggerAdapter } from '@/infra/logger';
import { interceptAxiosResponseError, requestRetry } from '../axios';
import { ApiInternalServerException } from '../exception';
import { TracingType } from '../request';
import { Context } from '@opentelemetry/api';

@Injectable()
export class HttpTracingInterceptor implements NestInterceptor {
Expand All @@ -36,14 +36,13 @@ export class HttpTracingInterceptor implements NestInterceptor {

this.tracer = initTracer(config, options);

const span = this.tracer.startSpan("MIKE");
const span = this.tracer.startSpan('MIKE');

span.log({ aff: 'AAAAAA' })
span.log({ aff: 'AAAAAA' });

span.finish()
span.finish();
}


intercept(executionContext: ExecutionContext, next: CallHandler): Observable<unknown> {
const request = executionContext.switchToHttp().getRequest();
const res = executionContext.switchToHttp().getResponse();
Expand All @@ -52,7 +51,7 @@ export class HttpTracingInterceptor implements NestInterceptor {
const parentObject = parent ? { childOf: parent } : {};
const span = this.tracer.startSpan(request.headers.host + request.path, parentObject);

span.log({ aff: 'AAAAAA' })
span.log({ aff: 'AAAAAA' });
const requestId = request.headers.traceid ?? request.id;

const createJaegerInstance = (): any => {
Expand Down
54 changes: 24 additions & 30 deletions src/utils/interceptors/open-tracing.interceptor.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
import { CallHandler, ExecutionContext, Injectable, NestInterceptor } from '@nestjs/common';
import opentelemetry, {
AttributeValue,
Context,
SpanAttributes,
SpanKind,
SpanOptions,
SpanStatus,
TimeInput,
Tracer
} from '@opentelemetry/api';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
import { registerInstrumentations } from '@opentelemetry/instrumentation';
import { ExpressInstrumentation } from '@opentelemetry/instrumentation-express';
import { HttpInstrumentation } from '@opentelemetry/instrumentation-http';
import { NestInstrumentation } from '@opentelemetry/instrumentation-nestjs-core';
import { Resource } from '@opentelemetry/resources';
import { BasicTracerProvider, BatchSpanProcessor, ConsoleSpanExporter } from '@opentelemetry/sdk-trace-node';
import { SemanticAttributes, SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import axios, { AxiosInstance, AxiosRequestConfig } from 'axios';
import axiosBetterStacktrace from 'axios-better-stacktrace';
import { DateTime } from 'luxon';
import { Resource } from '@opentelemetry/resources';
import { name, version } from 'package.json';
import { Observable, tap } from 'rxjs';

Expand All @@ -11,32 +28,12 @@ import { ILoggerAdapter } from '@/infra/logger';
import { interceptAxiosResponseError, requestRetry } from '../axios';
import { ApiInternalServerException } from '../exception';
import { TracingType } from '../request';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';


import opentelemetry, {
Tracer,
SpanKind,
SpanOptions,
AttributeValue,
SpanAttributes,
TimeInput,
SpanStatus,
Context
} from '@opentelemetry/api';
import { registerInstrumentations } from '@opentelemetry/instrumentation';
import { ExpressInstrumentation } from '@opentelemetry/instrumentation-express';
import { HttpInstrumentation } from '@opentelemetry/instrumentation-http';
import { BatchSpanProcessor, ConsoleSpanExporter, BasicTracerProvider } from '@opentelemetry/sdk-trace-node';
import { SemanticAttributes, SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import { NestInstrumentation } from '@opentelemetry/instrumentation-nestjs-core';

@Injectable()
export class OpenTracingInterceptor implements NestInterceptor {
private tracer: Tracer;

constructor(private readonly logger: ILoggerAdapter) {

// const provider = new BasicTracerProvider({
// resource: new Resource({
// [SemanticResourceAttributes.SERVICE_NAME]: name,
Expand All @@ -45,15 +42,13 @@ export class OpenTracingInterceptor implements NestInterceptor {
// })
// });


// const traceExporter = new OTLPTraceExporter();

// const exporter = new ConsoleSpanExporter();

// provider.addSpanProcessor(new BatchSpanProcessor(traceExporter));
// provider.addSpanProcessor(new BatchSpanProcessor(exporter));


// registerInstrumentations({
// instrumentations: [new ExpressInstrumentation(), new HttpInstrumentation({
// requestHook: (span, request) => {
Expand All @@ -65,14 +60,14 @@ export class OpenTracingInterceptor implements NestInterceptor {

// provider.register()

this.tracer = opentelemetry.trace.getTracerProvider().getTracer(name, version)
this.tracer = opentelemetry.trace.getTracerProvider().getTracer(name, version);

const span = this.tracer.startSpan('ola')
const span = this.tracer.startSpan('ola');

span.addEvent('AFF', { TESTE: 'aff' })
span.addEvent('AFF', { TESTE: 'aff' });

span.setAttribute('stop', "EITGH")
span.end()
span.setAttribute('stop', 'EITGH');
span.end();
}

intercept(executionContext: ExecutionContext, next: CallHandler): Observable<unknown> {
Expand All @@ -90,7 +85,6 @@ export class OpenTracingInterceptor implements NestInterceptor {
tracerId: requestId,
attributes: SemanticAttributes,
axios: (options: AxiosRequestConfig = {}): AxiosInstance => {

if (request.headers.authorization) {
options.headers['authorization'] = `${request.headers.authorization}`;
}
Expand Down Expand Up @@ -126,7 +120,7 @@ export class OpenTracingInterceptor implements NestInterceptor {
span.end();
},
createSpan: (name, parent: Context) => {
return this.tracer.startSpan(name, { root: false, }, parent);
return this.tracer.startSpan(name, { root: false }, parent);
}
};
};
Expand Down
6 changes: 3 additions & 3 deletions src/utils/request.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { AttributeValue, Context, SpanStatus, TimeInput } from '@opentelemetry/api';
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
import { AxiosInstance, AxiosRequestConfig } from 'axios';

// import { JaegerTracer } from 'jaeger-client';
// import { Span, Tags } from 'opentracing';

import { UserEntity } from '@/core/user/entity/user';
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
import { AttributeValue, Context, SpanStatus, TimeInput } from '@opentelemetry/api';

type LogEventType = AttributeValue | TimeInput;

Expand Down
30 changes: 15 additions & 15 deletions src/utils/tracing.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
import { Resource } from '@opentelemetry/resources';
import { name, version } from '../../package.json';

import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';

import { registerInstrumentations } from '@opentelemetry/instrumentation';
import { ExpressInstrumentation } from '@opentelemetry/instrumentation-express';
import { HttpInstrumentation } from '@opentelemetry/instrumentation-http';
import { BatchSpanProcessor, ConsoleSpanExporter, BasicTracerProvider } from '@opentelemetry/sdk-trace-node';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import { NestInstrumentation } from '@opentelemetry/instrumentation-nestjs-core';
import { Resource } from '@opentelemetry/resources';
import { BasicTracerProvider, BatchSpanProcessor, ConsoleSpanExporter } from '@opentelemetry/sdk-trace-node';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';

import { name, version } from '../../package.json';

const provider = new BasicTracerProvider({
resource: new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: name,
[SemanticResourceAttributes.SERVICE_VERSION]: version,
"sevice.name": "AFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
'sevice.name': 'AFFFFFFFFFFFFFFFFFFFFFFFFFFFFF'
})
});


const traceExporter = new OTLPTraceExporter({ hostname: 'localhost' });

const exporter = new ConsoleSpanExporter();

provider.addSpanProcessor(new BatchSpanProcessor(traceExporter));
provider.addSpanProcessor(new BatchSpanProcessor(exporter));


registerInstrumentations({
instrumentations: [new ExpressInstrumentation(), new HttpInstrumentation({
requestHook: (span, request) => {
span.setAttribute("custom_request", "request");
},
}), new NestInstrumentation()],
instrumentations: [
new ExpressInstrumentation(),
new HttpInstrumentation({
requestHook: (span, request) => {
span.setAttribute('custom_request', 'request');
}
}),
new NestInstrumentation()
]
});

provider.register()
provider.register();

0 comments on commit 2efa10e

Please sign in to comment.