-
Notifications
You must be signed in to change notification settings - Fork 4.5k
chore: Distributed tracing for client #37101
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
Changes from all commits
554635b
732ab2d
576b5da
1cd8075
c32f0d5
0cefb16
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,12 +4,11 @@ import { ZoneContextManager } from "@opentelemetry/context-zone"; | |
| import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-proto"; | ||
| import { Resource } from "@opentelemetry/resources"; | ||
| import { | ||
| SEMRESATTRS_SERVICE_NAME, | ||
| SEMRESATTRS_SERVICE_VERSION, | ||
| SEMRESATTRS_SERVICE_INSTANCE_ID, | ||
| } from "@opentelemetry/semantic-conventions"; | ||
| ATTR_DEPLOYMENT_NAME, | ||
| ATTR_SERVICE_INSTANCE_ID, | ||
| } from "@opentelemetry/semantic-conventions/incubating"; | ||
| import { ATTR_SERVICE_NAME } from "@opentelemetry/semantic-conventions"; | ||
| import { getAppsmithConfigs } from "ee/configs"; | ||
| import { W3CTraceContextPropagator } from "@opentelemetry/core"; | ||
| import { | ||
| MeterProvider, | ||
| PeriodicExportingMetricReader, | ||
|
|
@@ -18,33 +17,29 @@ import { | |
| OTLPMetricExporter, | ||
| AggregationTemporalityPreference, | ||
| } from "@opentelemetry/exporter-metrics-otlp-http"; | ||
| import type { Context, TextMapSetter } from "@opentelemetry/api"; | ||
| import { metrics } from "@opentelemetry/api"; | ||
| import { registerInstrumentations } from "@opentelemetry/instrumentation"; | ||
| import { PageLoadInstrumentation } from "./PageLoadInstrumentation"; | ||
| import { getWebAutoInstrumentations } from "@opentelemetry/auto-instrumentations-web"; | ||
|
|
||
| enum CompressionAlgorithm { | ||
| NONE = "none", | ||
| GZIP = "gzip", | ||
| } | ||
| const { newRelic } = getAppsmithConfigs(); | ||
| const { | ||
| applicationId, | ||
| browserAgentEndpoint, | ||
| otlpEndpoint, | ||
| otlpLicenseKey, | ||
| otlpServiceName, | ||
| } = newRelic; | ||
| const { newRelic, observability } = getAppsmithConfigs(); | ||
| const { browserAgentEndpoint, otlpEndpoint, otlpLicenseKey } = newRelic; | ||
|
|
||
| const { deploymentName, serviceInstanceId, serviceName } = observability; | ||
|
|
||
| // This base domain is used to filter out the Smartlook requests from the browser agent | ||
| // There are some requests made to subdomains of smartlook.cloud which will also be filtered out | ||
| const smartlookBaseDomain = "smartlook.cloud"; | ||
|
|
||
| const tracerProvider = new WebTracerProvider({ | ||
| resource: new Resource({ | ||
| [SEMRESATTRS_SERVICE_NAME]: otlpServiceName, | ||
| [SEMRESATTRS_SERVICE_INSTANCE_ID]: applicationId, | ||
| [SEMRESATTRS_SERVICE_VERSION]: "1.0.0", | ||
| [ATTR_DEPLOYMENT_NAME]: deploymentName, | ||
| [ATTR_SERVICE_INSTANCE_ID]: serviceInstanceId, | ||
| [ATTR_SERVICE_NAME]: serviceName, | ||
| }), | ||
| }); | ||
|
|
||
|
|
@@ -71,32 +66,9 @@ const processor = new BatchSpanProcessor( | |
| }, | ||
| ); | ||
|
|
||
| const W3C_OTLP_TRACE_HEADER = "traceparent"; | ||
| const CUSTOM_OTLP_TRACE_HEADER = "traceparent-otlp"; | ||
|
|
||
| //We are overriding the default header "traceparent" used for trace context because the browser | ||
| // agent shares the same header's distributed tracing | ||
| class CustomW3CTraceContextPropagator extends W3CTraceContextPropagator { | ||
| inject( | ||
| context: Context, | ||
| carrier: Record<string, unknown>, | ||
| setter: TextMapSetter, | ||
| ) { | ||
| // Call the original inject method to get the default traceparent header | ||
| super.inject(context, carrier, setter); | ||
|
|
||
| // Modify the carrier to use a different header | ||
| if (carrier[W3C_OTLP_TRACE_HEADER]) { | ||
| carrier[CUSTOM_OTLP_TRACE_HEADER] = carrier[W3C_OTLP_TRACE_HEADER]; | ||
| delete carrier[W3C_OTLP_TRACE_HEADER]; // Remove the original traceparent header | ||
| } | ||
| } | ||
| } | ||
|
|
||
| tracerProvider.addSpanProcessor(processor); | ||
| tracerProvider.register({ | ||
| contextManager: new ZoneContextManager(), | ||
| propagator: new CustomW3CTraceContextPropagator(), | ||
| }); | ||
|
|
||
| const nrMetricsExporter = new OTLPMetricExporter({ | ||
|
|
@@ -110,9 +82,9 @@ const nrMetricsExporter = new OTLPMetricExporter({ | |
|
|
||
| const meterProvider = new MeterProvider({ | ||
| resource: new Resource({ | ||
| [SEMRESATTRS_SERVICE_NAME]: otlpServiceName, | ||
| [SEMRESATTRS_SERVICE_INSTANCE_ID]: applicationId, | ||
| [SEMRESATTRS_SERVICE_VERSION]: "1.0.0", | ||
| [ATTR_DEPLOYMENT_NAME]: deploymentName, | ||
| [ATTR_SERVICE_INSTANCE_ID]: serviceInstanceId, | ||
| [ATTR_SERVICE_NAME]: serviceName, | ||
| }), | ||
| readers: [ | ||
| new PeriodicExportingMetricReader({ | ||
|
|
@@ -136,5 +108,10 @@ registerInstrumentations({ | |
| smartlookBaseDomain, | ||
| ], | ||
| }), | ||
| getWebAutoInstrumentations({ | ||
nidhi-nair marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "@opentelemetry/instrumentation-xml-http-request": { | ||
| enabled: true, | ||
| }, | ||
| }), | ||
|
Comment on lines
+111
to
+115
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider additional XHR instrumentation configuration While the basic setup is good, consider enhancing the XHR instrumentation with:
Example configuration: getWebAutoInstrumentations({
"@opentelemetry/instrumentation-xml-http-request": {
enabled: true,
+ ignoreUrls: [browserAgentEndpoint, otlpEndpoint, smartlookBaseDomain],
+ propagateTraceHeaderCorsUrls: /.*/, // Configure URLs where trace headers should be propagated
+ clearTimingResources: true,
},
}),
|
||
| ], | ||
| }); | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -8,8 +8,6 @@ import axios from "axios"; | |||||
| import type { Action, ActionViewMode } from "entities/Action"; | ||||||
| import type { APIRequest } from "constants/AppsmithActionConstants/ActionConstants"; | ||||||
| import type { WidgetType } from "constants/WidgetConstants"; | ||||||
| import type { OtlpSpan } from "UITelemetry/generateTraces"; | ||||||
| import { wrapFnWithParentTraceContext } from "UITelemetry/generateTraces"; | ||||||
| import type { ActionParentEntityTypeInterface } from "ee/entities/Engine/actionHelpers"; | ||||||
|
|
||||||
| export interface Property { | ||||||
|
|
@@ -233,17 +231,10 @@ class ActionAPI extends API { | |||||
| static async executeAction( | ||||||
| executeAction: FormData, | ||||||
| timeout?: number, | ||||||
| parentSpan?: OtlpSpan, | ||||||
| ): Promise<AxiosPromise<ActionExecutionResponse>> { | ||||||
| ActionAPI.abortActionExecutionTokenSource = axios.CancelToken.source(); | ||||||
|
|
||||||
| if (!parentSpan) { | ||||||
| return this.executeApiCall(executeAction, timeout); | ||||||
| } | ||||||
|
|
||||||
| return wrapFnWithParentTraceContext(parentSpan, async () => { | ||||||
| return await this.executeApiCall(executeAction, timeout); | ||||||
| }); | ||||||
| return await this.executeApiCall(executeAction, timeout); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace Using Apply this fix: - return await this.executeApiCall(executeAction, timeout);
+ return await ActionAPI.executeApiCall(executeAction, timeout);📝 Committable suggestion
Suggested change
🧰 Tools🪛 Biome
|
||||||
| } | ||||||
|
|
||||||
| static async moveAction(moveRequest: MoveActionRequest) { | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Consider extracting duplicate resource configuration
The same resource configuration is duplicated between tracer and meter providers.
Consider extracting the resource configuration:
Also applies to: 85-87