-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
53 lines (47 loc) · 1.43 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import opentelemetry from "@opentelemetry/api";
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
import { Resource } from "@opentelemetry/resources";
import {
BasicTracerProvider,
SimpleSpanProcessor,
} from "@opentelemetry/sdk-trace-base";
import { SemanticResourceAttributes } from "@opentelemetry/semantic-conventions";
import { ApolloServer } from "apollo-server";
import cluster from "cluster";
import { cpus } from "os";
process.env.PORT = "8000";
const provider = new BasicTracerProvider({
resource: new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: "basic-service",
}),
});
const exporter = new OTLPTraceExporter({});
provider.addSpanProcessor(new SimpleSpanProcessor(exporter));
provider.register();
if (cluster.isPrimary) {
for (let i = 0; i < cpus().length; i++) {
cluster.fork();
}
} else {
const server = new ApolloServer({
typeDefs: `
type Query {
hello: String!
}
`,
resolvers: {
Query: {
hello: (root, args, context, info) => {
const tracer = opentelemetry.trace.getTracer("example-tracer");
const span = tracer.startSpan("say-hello");
span.setAttribute("hello-to", "world");
span.setAttribute("query", JSON.stringify(info.operation));
span.addEvent("invoking resolvers");
span.end();
return "world";
},
},
},
});
server.listen(8000);
}