Skip to content

Commit e4d2ced

Browse files
committed
fix source when streaming
1 parent 07ddbd6 commit e4d2ced

2 files changed

Lines changed: 15 additions & 10 deletions

File tree

‎packages/google-cloud-serverless/src/gcpfunction/http.ts‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,11 @@ function _wrapHttpFunction(fn: HttpFunction, options: Partial<WrapperOptions>):
5959
const normalizedRequest = httpRequestToRequestData(req);
6060
getCurrentScope().setSDKProcessingMetadata({ normalizedRequest });
6161

62-
const client = getClient();
63-
6462
const functionName = getFunctionName();
65-
const name =
66-
client && hasSpanStreamingEnabled(client)
67-
? functionName || SERVERLESS_FUNCTION_SPAN_NAME_FALLBACK
68-
: `${reqMethod} ${reqUrl}`;
63+
64+
const client = getClient();
65+
const hasSpanStreaming = client && hasSpanStreamingEnabled(client);
66+
const name = hasSpanStreaming ? functionName || SERVERLESS_FUNCTION_SPAN_NAME_FALLBACK : `${reqMethod} ${reqUrl}`;
6967

7068
return startSpanManual(
7169
{
@@ -74,7 +72,7 @@ function _wrapHttpFunction(fn: HttpFunction, options: Partial<WrapperOptions>):
7472
[SENTRY_OP]: FUNCTION_GCP,
7573
[FAAS_NAME]: functionName,
7674
[FAAS_TRIGGER]: 'http',
77-
[SENTRY_SEGMENT_NAME_SOURCE]: 'route',
75+
[SENTRY_SEGMENT_NAME_SOURCE]: hasSpanStreaming ? 'component' : 'route',
7876
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.function.serverless.gcp_http',
7977
// The method and path used to be the span name; they stay on the span so that
8078
// information survives the low-cardinality rename.

‎packages/google-cloud-serverless/test/gcpfunction/http.test.ts‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ describe('GCPFunction', () => {
215215
// The method and path stay on the span even though they are no longer the name.
216216
[HTTP_REQUEST_METHOD]: 'POST',
217217
[URL_PATH]: '/path',
218+
[SENTRY_SEGMENT_NAME_SOURCE]: 'component',
218219
}),
219220
}),
220221
expect.any(Function),
@@ -233,7 +234,10 @@ describe('GCPFunction', () => {
233234
expect(mockStartSpanManual).toBeCalledWith(
234235
expect.objectContaining({
235236
name: 'my-cloud-run-service',
236-
attributes: expect.objectContaining({ [FAAS_NAME]: 'my-cloud-run-service' }),
237+
attributes: expect.objectContaining({
238+
[FAAS_NAME]: 'my-cloud-run-service',
239+
[SENTRY_SEGMENT_NAME_SOURCE]: 'component',
240+
}),
237241
}),
238242
expect.any(Function),
239243
);
@@ -251,7 +255,7 @@ describe('GCPFunction', () => {
251255
expect(mockStartSpanManual).toBeCalledWith(
252256
expect.objectContaining({
253257
name: SERVERLESS_FUNCTION_SPAN_NAME_FALLBACK,
254-
attributes: expect.objectContaining({ [FAAS_NAME]: undefined }),
258+
attributes: expect.objectContaining({ [FAAS_NAME]: undefined, [SENTRY_SEGMENT_NAME_SOURCE]: 'component' }),
255259
}),
256260
expect.any(Function),
257261
);
@@ -283,7 +287,10 @@ describe('GCPFunction', () => {
283287
expect(mockStartSpanManual).toBeCalledWith(
284288
expect.objectContaining({
285289
name: 'POST /path',
286-
attributes: expect.objectContaining({ [FAAS_NAME]: 'myCloudFunction' }),
290+
attributes: expect.objectContaining({
291+
[FAAS_NAME]: 'myCloudFunction',
292+
[SENTRY_SEGMENT_NAME_SOURCE]: 'route',
293+
}),
287294
}),
288295
expect.any(Function),
289296
);

0 commit comments

Comments
 (0)