Skip to content

Commit

Permalink
Code review. Lint warnings. Stop using deprecated types.
Browse files Browse the repository at this point in the history
  • Loading branch information
klippx committed Oct 1, 2023
1 parent 24fdf41 commit a410833
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
SpanStatusCode,
trace,
Histogram,
MetricAttributes,
Attributes,
ValueType,
} from '@opentelemetry/api';
import {
Expand Down Expand Up @@ -310,7 +310,7 @@ export class HttpInstrumentation extends InstrumentationBase<Http> {
request: http.ClientRequest,
span: Span,
startTime: HrTime,
metricAttributes: MetricAttributes
metricAttributes: Attributes
): http.ClientRequest {
if (this._getConfig().requestHook) {
this._callRequestHook(span, request);
Expand Down Expand Up @@ -376,7 +376,7 @@ export class HttpInstrumentation extends InstrumentationBase<Http> {
if (this._getConfig().applyCustomAttributesOnSpan) {
safeExecuteInTheMiddle(
() =>
this._getConfig().applyCustomAttributesOnSpan!(
this._getConfig().applyCustomAttributesOnSpan?.(
span,
request,
response
Expand Down Expand Up @@ -512,9 +512,14 @@ export class HttpInstrumentation extends InstrumentationBase<Http> {
};

const startTime = hrTime();
const metricAttributes: MetricAttributes = Object.assign(
const customMetricAttributes = safeExecuteInTheMiddle(
() => instrumentation._getConfig().customMetricAttributes?.(),
() => {},
true
);
const metricAttributes: Attributes = Object.assign(
utils.getIncomingRequestMetricAttributes(spanAttributes),
instrumentation._getConfig().customMetricAttributes?.()
customMetricAttributes
);

const ctx = propagation.extract(ROOT_CONTEXT, headers);
Expand Down Expand Up @@ -660,9 +665,14 @@ export class HttpInstrumentation extends InstrumentationBase<Http> {
});

const startTime = hrTime();
const metricAttributes: MetricAttributes = Object.assign(
const customMetricAttributes = safeExecuteInTheMiddle(
() => instrumentation._getConfig().customMetricAttributes?.(),
() => {},
true
);
const metricAttributes: Attributes = Object.assign(
utils.getOutgoingRequestMetricAttributes(attributes),
instrumentation._getConfig().customMetricAttributes?.()
customMetricAttributes
);

const spanOptions: SpanOptions = {
Expand Down Expand Up @@ -723,7 +733,7 @@ export class HttpInstrumentation extends InstrumentationBase<Http> {
request: http.IncomingMessage,
response: http.ServerResponse,
span: Span,
metricAttributes: MetricAttributes,
metricAttributes: Attributes,
startTime: HrTime
) {
const attributes = utils.getIncomingRequestAttributesOnResponse(
Expand Down Expand Up @@ -751,7 +761,7 @@ export class HttpInstrumentation extends InstrumentationBase<Http> {
if (this._getConfig().applyCustomAttributesOnSpan) {
safeExecuteInTheMiddle(
() =>
this._getConfig().applyCustomAttributesOnSpan!(
this._getConfig().applyCustomAttributesOnSpan?.(
span,
request,
response
Expand All @@ -766,7 +776,7 @@ export class HttpInstrumentation extends InstrumentationBase<Http> {

private _onServerResponseError(
span: Span,
metricAttributes: MetricAttributes,
metricAttributes: Attributes,
startTime: HrTime,
error: Err
) {
Expand Down Expand Up @@ -806,7 +816,7 @@ export class HttpInstrumentation extends InstrumentationBase<Http> {
span: Span,
spanKind: SpanKind,
startTime: HrTime,
metricAttributes: MetricAttributes
metricAttributes: Attributes
) {
if (!this._spanNotEnded.has(span)) {
return;
Expand All @@ -829,7 +839,7 @@ export class HttpInstrumentation extends InstrumentationBase<Http> {
response: http.IncomingMessage | http.ServerResponse
) {
safeExecuteInTheMiddle(
() => this._getConfig().responseHook!(span, response),
() => this._getConfig().responseHook?.(span, response),
() => {},
true
);
Expand All @@ -840,7 +850,7 @@ export class HttpInstrumentation extends InstrumentationBase<Http> {
request: http.ClientRequest | http.IncomingMessage
) {
safeExecuteInTheMiddle(
() => this._getConfig().requestHook!(span, request),
() => this._getConfig().requestHook?.(span, request),
() => {},
true
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { MetricAttributes, Span, SpanAttributes } from '@opentelemetry/api';
import { Attributes, Span } from '@opentelemetry/api';
import type * as http from 'http';
import type * as https from 'https';
import {
Expand Down Expand Up @@ -73,15 +73,15 @@ export interface HttpResponseCustomAttributeFunction {
}

export interface StartIncomingSpanCustomAttributeFunction {
(request: IncomingMessage): SpanAttributes;
(request: IncomingMessage): Attributes;
}

export interface StartOutgoingSpanCustomAttributeFunction {
(request: RequestOptions): SpanAttributes;
(request: RequestOptions): Attributes;
}

export interface CustomMetricAttributeFunction {
(): MetricAttributes;
(): Attributes;
}

/**
Expand Down

0 comments on commit a410833

Please sign in to comment.