PromucFlow_constructor/app/client/packages/rts/src/instrumentation.ts
Subhrashis Das c70adf7440
chore: Switch from OTLP HTTP/protobuf (New Relic) to HTTP/JSON (Grafana) (#37404)
## Description
> [!TIP]  
> _Add a TL;DR when the description is longer than 500 words or
extremely technical (helps the content, marketing, and DevRel team)._
>
> _Please also include relevant motivation and context. List any
dependencies that are required for this change. Add links to Notion,
Figma or any other documents that might be relevant to the PR._


Fixes #`Issue Number`  
_or_  
Fixes `Issue URL`
> [!WARNING]  
> _If no issue exists, please create an issue first, and check with the
maintainers if the issue is valid._

## Automation

/ok-to-test tags=""

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!WARNING]
> Tests have not run on the HEAD
065cddccdcf3c98cb48ff201daf752708f24666c yet
> <hr>Fri, 15 Nov 2024 11:48:13 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Introduced new monitoring paths for telemetry data exports:
`/monitoring/traces` and `/monitoring/metrics`.
	- Added a function to streamline URL management for telemetry exports.

- **Bug Fixes**
- Updated telemetry export protocols to enhance reliability and
performance.

- **Chores**
- Updated multiple OpenTelemetry dependencies to their latest versions
for improved functionality and security.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-11-18 05:59:33 +00:00

55 lines
1.8 KiB
TypeScript

import {
BatchSpanProcessor,
NodeTracerProvider,
} from "@opentelemetry/sdk-trace-node";
import { Resource } from "@opentelemetry/resources";
import {
ATTR_DEPLOYMENT_NAME,
ATTR_SERVICE_INSTANCE_ID,
} from "@opentelemetry/semantic-conventions/incubating";
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-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({
[ATTR_DEPLOYMENT_NAME]: `${process.env.APPSMITH_DEPLOYMENT_NAME || "self-hosted"}`,
[ATTR_SERVICE_INSTANCE_ID]: `${process.env.HOSTNAME || "appsmith-0"}`,
[ATTR_SERVICE_NAME]: "appsmith-rts",
}),
});
const nrTracesExporter = new OTLPTraceExporter({
url: `${APPSMITH_NEW_RELIC_OTEL_EXPORTER_OTLP_ENDPOINT}/v1/traces`,
headers: {
"api-key": `${process.env.APPSMITH_NEW_RELIC_OTLP_LICENSE_KEY}`,
},
});
registerInstrumentations({
instrumentations: [new HttpInstrumentation()],
});
const batchSpanProcessor = new BatchSpanProcessor(
nrTracesExporter,
//Optional BatchSpanProcessor Configurations
{
// The maximum queue size. After the size is reached spans are dropped.
maxQueueSize: 100,
// The maximum batch size of every export. It must be smaller or equal to maxQueueSize.
maxExportBatchSize: 50,
// The interval between two consecutive exports
scheduledDelayMillis: 500,
// How long the export can run before it is cancelled
exportTimeoutMillis: 30000,
},
);
provider.addSpanProcessor(batchSpanProcessor);
provider.register();