@sentry/google-cloud-serverless
Version:
Official Sentry SDK for Google Cloud Functions
37 lines (34 loc) • 1.24 kB
JavaScript
import { defineIntegration, getCurrentScope, safeSetSpanJSONAttributes } from '@sentry/core';
const GCP_CONTEXT_ATTRIBUTE_MAP = {
type: "gcp.function.context.type",
source: "gcp.function.context.source",
id: "gcp.function.context.id",
specversion: "gcp.function.context.specversion",
time: "gcp.function.context.time",
eventId: "gcp.function.context.event_id",
timestamp: "gcp.function.context.timestamp",
eventType: "gcp.function.context.event_type",
resource: "gcp.function.context.resource"
};
const _gcpContextIntegration = (() => {
return {
name: "GcpContext",
processSegmentSpan(span) {
const gcpContext = getCurrentScope().getScopeData().contexts["gcp.function.context"];
if (!gcpContext) {
return;
}
const attrs = {};
for (const [field, attrName] of Object.entries(GCP_CONTEXT_ATTRIBUTE_MAP)) {
const value = gcpContext[field];
if (typeof value === "string" || typeof value === "number") {
attrs[attrName] = value;
}
}
safeSetSpanJSONAttributes(span, attrs);
}
};
});
const gcpContextIntegration = defineIntegration(_gcpContextIntegration);
export { gcpContextIntegration };
//# sourceMappingURL=gcp-context.js.map