Skip to content

Commit

Permalink
DEVPROD-11410 Don't init @opentelemetry/instrumentation-fetch if runn…
Browse files Browse the repository at this point in the history
…ing on parsley (#394)
  • Loading branch information
khelif96 authored Sep 18, 2024
1 parent 4cf404c commit b506375
Showing 1 changed file with 33 additions and 27 deletions.
60 changes: 33 additions & 27 deletions packages/lib/src/utils/observability/honeycomb.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { HoneycombWebSDK } from "@honeycombio/opentelemetry-web";
import { getWebAutoInstrumentations } from "@opentelemetry/auto-instrumentations-web";
import {
getWebAutoInstrumentations,
InstrumentationConfigMap,
} from "@opentelemetry/auto-instrumentations-web";
import { detectGraphqlQuery } from "./utils";

/**
Expand Down Expand Up @@ -47,36 +50,39 @@ const initializeHoneycomb = ({
} else {
try {
const userId = localStorage.getItem("userId") ?? undefined;
const webAutoInstrumentationConfig: InstrumentationConfigMap = {
"@opentelemetry/instrumentation-document-load": {
ignoreNetworkEvents: true,
},
};
if (serviceName !== "parsley") {
webAutoInstrumentationConfig["@opentelemetry/instrumentation-fetch"] = {
// Add GraphQL operation name as an attribute to HTTP traces.
applyCustomAttributesOnSpan: (span, request) => {
if (span && request) {
const { body } = request;
if (!body || typeof body !== "string") {
return;
}
const graphqlQuery = detectGraphqlQuery(body);
if (graphqlQuery) {
span.setAttribute(
"graphql.operation_name",
graphqlQuery.operationName,
);
span.setAttribute("graphql.query_type", graphqlQuery.queryType);
}
}
},
// Allow connecting frontend & backend traces.
propagateTraceHeaderCorsUrls: [new RegExp(backendURL || "")],
};
}
const honeycombSdk = new HoneycombWebSDK({
debug,
endpoint,
instrumentations: [
getWebAutoInstrumentations({
"@opentelemetry/instrumentation-fetch": {
// Add GraphQL operation name as an attribute to HTTP traces.
applyCustomAttributesOnSpan: (span, request) => {
if (span && request) {
const body = request.body as string;
const graphqlQuery = detectGraphqlQuery(body);
if (graphqlQuery) {
span.setAttribute(
"graphql.operation_name",
graphqlQuery.operationName,
);
span.setAttribute(
"graphql.query_type",
graphqlQuery.queryType,
);
}
}
},
// Allow connecting frontend & backend traces.
propagateTraceHeaderCorsUrls: [new RegExp(backendURL || "")],
},
"@opentelemetry/instrumentation-document-load": {
ignoreNetworkEvents: true,
},
}),
getWebAutoInstrumentations(webAutoInstrumentationConfig),
],
// Add user.id as an attribute to all traces.
resourceAttributes: {
Expand Down

0 comments on commit b506375

Please sign in to comment.