Skip to content

Commit

Permalink
Switch from OTLP HTTP/protobuf (New Relic) to HTTP/JSON (Grafana)
Browse files Browse the repository at this point in the history
  • Loading branch information
subhrashisdas committed Nov 15, 2024
1 parent 77bae7c commit 065cddc
Show file tree
Hide file tree
Showing 5 changed files with 186 additions and 219 deletions.
20 changes: 10 additions & 10 deletions app/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,16 @@
"@mantine/hooks": "^5.10.1",
"@newrelic/browser-agent": "^1.255.0",
"@opentelemetry/api": "^1.9.0",
"@opentelemetry/auto-instrumentations-web": "^0.41.0",
"@opentelemetry/context-zone": "1.25.1",
"@opentelemetry/core": "^1.26.0",
"@opentelemetry/exporter-metrics-otlp-http": "0.52.1",
"@opentelemetry/exporter-trace-otlp-proto": "0.52.1",
"@opentelemetry/instrumentation": "0.52.1",
"@opentelemetry/resources": "1.25.1",
"@opentelemetry/sdk-metrics": "1.25.1",
"@opentelemetry/sdk-trace-base": "1.25.1",
"@opentelemetry/sdk-trace-web": "1.25.1",
"@opentelemetry/auto-instrumentations-web": "^0.42.0",
"@opentelemetry/context-zone": "^1.27.0",
"@opentelemetry/core": "^1.27.0",
"@opentelemetry/exporter-metrics-otlp-http": "^0.54.2",
"@opentelemetry/exporter-trace-otlp-http": "^0.54.2",
"@opentelemetry/instrumentation": "^0.54.2",
"@opentelemetry/resources": "^1.27.0",
"@opentelemetry/sdk-metrics": "^1.27.0",
"@opentelemetry/sdk-trace-base": "^1.27.0",
"@opentelemetry/sdk-trace-web": "^1.27.0",
"@opentelemetry/semantic-conventions": "^1.27.0",
"@react-spring/web": "^9.7.4",
"@react-types/shared": "^3.23.0",
Expand Down
8 changes: 6 additions & 2 deletions app/client/packages/rts/src/instrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import {
import { ATTR_SERVICE_NAME } from "@opentelemetry/semantic-conventions";
import { registerInstrumentations } from "@opentelemetry/instrumentation";
import { HttpInstrumentation } from "@opentelemetry/instrumentation-http";
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-proto";
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";

const APPSMITH_NEW_RELIC_OTEL_EXPORTER_OTLP_ENDPOINT =
process.env.APPSMITH_NEW_RELIC_OTEL_EXPORTER_OTLP_ENDPOINT ||
"http://localhost:4318";

const provider = new NodeTracerProvider({
resource: new Resource({
Expand All @@ -21,7 +25,7 @@ const provider = new NodeTracerProvider({
});

const nrTracesExporter = new OTLPTraceExporter({
url: `${process.env.APPSMITH_NEW_RELIC_OTEL_EXPORTER_OTLP_ENDPOINT}/v1/traces`,
url: `${APPSMITH_NEW_RELIC_OTEL_EXPORTER_OTLP_ENDPOINT}/v1/traces`,
headers: {
"api-key": `${process.env.APPSMITH_NEW_RELIC_OTLP_LICENSE_KEY}`,
},
Expand Down
24 changes: 18 additions & 6 deletions app/client/src/UITelemetry/auto-otel-web.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BatchSpanProcessor } from "@opentelemetry/sdk-trace-base";
import { WebTracerProvider } from "@opentelemetry/sdk-trace-web";
import { ZoneContextManager } from "@opentelemetry/context-zone";
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-proto";
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
import { Resource } from "@opentelemetry/resources";
import {
ATTR_DEPLOYMENT_NAME,
Expand All @@ -14,8 +14,8 @@ import {
PeriodicExportingMetricReader,
} from "@opentelemetry/sdk-metrics";
import {
OTLPMetricExporter,
AggregationTemporalityPreference,
OTLPMetricExporter,
} from "@opentelemetry/exporter-metrics-otlp-http";
import { metrics } from "@opentelemetry/api";
import { registerInstrumentations } from "@opentelemetry/instrumentation";
Expand All @@ -27,7 +27,7 @@ enum CompressionAlgorithm {
GZIP = "gzip",
}
const { newRelic, observability } = getAppsmithConfigs();
const { browserAgentEndpoint, otlpEndpoint, otlpLicenseKey } = newRelic;
const { browserAgentEndpoint, otlpLicenseKey } = newRelic;

const { deploymentName, serviceInstanceId, serviceName } = observability;

Expand All @@ -44,7 +44,7 @@ const tracerProvider = new WebTracerProvider({
});

const nrTracesExporter = new OTLPTraceExporter({
url: `${otlpEndpoint}/v1/traces`,
url: addPathToCurrentUrl("/monitoring/traces"),
compression: CompressionAlgorithm.GZIP,
headers: {
"api-key": otlpLicenseKey,
Expand Down Expand Up @@ -74,7 +74,7 @@ tracerProvider.register({
const nrMetricsExporter = new OTLPMetricExporter({
compression: CompressionAlgorithm.GZIP,
temporalityPreference: AggregationTemporalityPreference.DELTA,
url: `${otlpEndpoint}/v1/metrics`,
url: addPathToCurrentUrl("/monitoring/metrics"),
headers: {
"api-key": otlpLicenseKey,
},
Expand Down Expand Up @@ -104,7 +104,8 @@ registerInstrumentations({
new PageLoadInstrumentation({
ignoreResourceUrls: [
browserAgentEndpoint,
otlpEndpoint,
addPathToCurrentUrl("/monitoring/traces"),
addPathToCurrentUrl("/monitoring/metrics"),
smartlookBaseDomain,
],
}),
Expand All @@ -115,3 +116,14 @@ registerInstrumentations({
}),
],
});

// Replaces the pathname of the current URL with the provided path.
function addPathToCurrentUrl(path: string) {
const origin = window.location.origin;

const currentUrl = new URL(origin);

currentUrl.pathname = path.startsWith("/") ? path : `/${path}`;

return currentUrl.toString();
}
Loading

0 comments on commit 065cddc

Please sign in to comment.