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

Add http route to outgoing http requests, if available #5129

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -421,6 +421,10 @@ export const getOutgoingRequestMetricAttributes = (
metricAttributes[SEMATTRS_HTTP_METHOD] = spanAttributes[SEMATTRS_HTTP_METHOD];
metricAttributes[SEMATTRS_NET_PEER_NAME] =
spanAttributes[SEMATTRS_NET_PEER_NAME];
const route = spanAttributes[SEMATTRS_HTTP_ROUTE];
if (route !== undefined) {
metricAttributes[SEMATTRS_HTTP_ROUTE] = route;
}
//TODO: http.url attribute, it should substitute any parameters to avoid high cardinality.
return metricAttributes;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import {
SEMATTRS_HTTP_RESPONSE_CONTENT_LENGTH_UNCOMPRESSED,
SEMATTRS_HTTP_ROUTE,
SEMATTRS_HTTP_TARGET,
SEMATTRS_HTTP_METHOD,
SEMATTRS_NET_PEER_NAME,
} from '@opentelemetry/semantic-conventions';
import * as assert from 'assert';
import { IncomingMessage, ServerResponse } from 'http';
Expand Down Expand Up @@ -279,6 +281,39 @@ describe('Utility', () => {
assert.deepEqual(metricAttributes[SEMATTRS_HTTP_ROUTE], undefined);
});
});

describe('getOutgoingRequestMetricAttributes()', () => {
it('should correctly add attributes from span', () => {
const spanAttributes: Attributes = {
[SEMATTRS_HTTP_METHOD]: 'GET',
[SEMATTRS_NET_PEER_NAME]: 'hostname',
[SEMATTRS_HTTP_ROUTE]: '/user/:id',
};
const metricAttributes =
utils.getOutgoingRequestMetricAttributes(spanAttributes);

assert.deepStrictEqual(metricAttributes[SEMATTRS_HTTP_METHOD], 'GET');
assert.deepStrictEqual(
metricAttributes[SEMATTRS_NET_PEER_NAME],
'hostname'
);
assert.deepStrictEqual(
metricAttributes[SEMATTRS_HTTP_ROUTE],
'/user/:id'
);
});

it('should not add http_route attribute if span does not have it', () => {
const spanAttributes: Attributes = {};
const metricAttributes =
utils.getOutgoingRequestMetricAttributes(spanAttributes);
assert.deepStrictEqual(metricAttributes, {
[SEMATTRS_HTTP_METHOD]: undefined,
[SEMATTRS_NET_PEER_NAME]: undefined,
});
});
});

// Verify the key in the given attributes is set to the given value,
// and that no other HTTP Content Length attributes are set.
function verifyValueInAttributes(
Expand Down