Skip to content

Commit 8ffdad4

Browse files
authored
Merge pull request #34 from MediaJel/staging
Staging
2 parents a025538 + cdeec6f commit 8ffdad4

File tree

7 files changed

+1570
-2
lines changed

7 files changed

+1570
-2
lines changed

chart/stages/production.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ global:
1212
environment: PRODUCTION
1313
salesForceChannel: "live" # Must either be "live" or "test", production must use "live"
1414
intuitEnvironment: production
15+
service_name: "Salesforce Automation"

chart/stages/staging.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ global:
1313
environment: STAGE
1414
salesForceChannel: "live" # Must either be "live" or "test", production must use "live"
1515
intuitEnvironment: sandbox
16+
service_name: "Salesforce Automation"

chart/templates/salesforce.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ spec:
8282
memory: |-
8383
{{ .Values.memoryRequest }}
8484
env:
85+
- name: SERVICE_NAME
86+
value: |-
87+
{{ .Values.service_name }}
8588
- name: GRAPHQL_ENDPOINT
8689
value: |-
8790
{{ .Values.gqlEndpoint }}

package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@
1616
"@graphql-codegen/client-preset": "^1.1.4",
1717
"@types/jsforce": "^1.11.0",
1818
"@types/node": "^18.11.9",
19+
"@opentelemetry/api": "1.7.0",
20+
"@opentelemetry/auto-instrumentations-node": "^0.48.0",
21+
"@opentelemetry/exporter-trace-otlp-http": "^0.45.0",
22+
"@opentelemetry/instrumentation-express": "^0.41.1",
23+
"@opentelemetry/instrumentation-http": "^0.57.0",
24+
"@opentelemetry/instrumentation-nestjs-core": "^0.39.0",
25+
"@opentelemetry/instrumentation-pino": "^0.41.0",
26+
"@opentelemetry/sdk-node": "^0.45.0",
27+
"pino-opentelemetry-transport": "^1.0.1",
1928
"nodemon": "^2.0.20",
2029
"rimraf": "^3.0.2",
2130
"ts-node": "^10.9.1"

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import createApp from '@/app';
22
import config from '@/config';
33
import createLogger from '@/utils/logger';
4+
import tracer from "./tracer";
45

56
const logger = createLogger("Index");
67
logger.info(`Logging set to ${config.logLevel} mode`);
78

89
const startApp = async () => {
10+
await tracer.start();
911
const app = await createApp(config);
1012

1113
await app.start();

src/tracer.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
'use strict';
2+
3+
import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
4+
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
5+
import { ExpressInstrumentation } from '@opentelemetry/instrumentation-express';
6+
import { HttpInstrumentation } from '@opentelemetry/instrumentation-http';
7+
import { NestInstrumentation } from '@opentelemetry/instrumentation-nestjs-core';
8+
import { PinoInstrumentation } from '@opentelemetry/instrumentation-pino';
9+
import { Resource } from '@opentelemetry/resources';
10+
import * as opentelemetry from '@opentelemetry/sdk-node';
11+
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
12+
13+
// Configure the SDK to export telemetry data to the console
14+
// Enable all auto-instrumentations from the meta package
15+
const exporterOptions = {
16+
url: 'http://otelcollector.dmp.cnna.io/v1/traces',
17+
};
18+
// http://localhost:4318/v1/traces
19+
20+
const traceExporter = new OTLPTraceExporter(exporterOptions);
21+
const sdk = new opentelemetry.NodeSDK({
22+
traceExporter,
23+
instrumentations: [
24+
getNodeAutoInstrumentations(),
25+
new NestInstrumentation(),
26+
new PinoInstrumentation(),
27+
new HttpInstrumentation(),
28+
new ExpressInstrumentation(),
29+
],
30+
resource: new Resource({
31+
[SemanticResourceAttributes.SERVICE_NAME]: 'salesforce-automation',
32+
[SemanticResourceAttributes.DEPLOYMENT_ENVIRONMENT]: process.env.NODE_ENV || 'local',
33+
}),
34+
});
35+
36+
// initialize the SDK and register with the OpenTelemetry API
37+
// this enables the API to record telemetry
38+
sdk.start();
39+
40+
// gracefully shut down the SDK on process exit
41+
process.on("SIGTERM", () => {
42+
sdk
43+
.shutdown()
44+
.then(() => console.log("Tracing terminated"))
45+
.catch((error) => console.log("Error terminating tracing", error))
46+
.finally(() => process.exit(0));
47+
});
48+
49+
export default sdk;

0 commit comments

Comments
 (0)