const os = require("os");
const { NodeSDK } = require("@opentelemetry/sdk-node");
const { NodeTracerProvider } = require("@opentelemetry/sdk-trace-node");
const {
PeriodicExportingMetricReader,
AggregationTemporality,
} = require("@opentelemetry/sdk-metrics");
const { resourceFromAttributes } = require("@opentelemetry/resources");
const { ATTR_SERVICE_NAME } = require("@opentelemetry/semantic-conventions");
const {
OTLPTraceExporter,
} = require("@opentelemetry/exporter-trace-otlp-proto");
const {
OTLPMetricExporter,
} = require("@opentelemetry/exporter-metrics-otlp-proto");
const {
getNodeAutoInstrumentations,
} = require("@opentelemetry/auto-instrumentations-node");
// Replace these values with your AppSignal application name, environment
// and push API key. These are used by the resource attributes configuration below.
const name = "My app";
const pushApiKey = "0000-0000-0000-0000";
const environment = process.env.NODE_ENV || "production";
// Set the name of the service that is being monitored. A common choice is the
// name of the framework used. This is used to group traces and metrics in AppSignal.
const serviceName = "My service name";
// Replace `http://localhost:8099` with the address of your AppSignal collector
// if it's running on another host.
const endpoint = "http://localhost:8099";
const revision = childProcess.execSync("git rev-parse --short HEAD").toString();
const resource = new resourceFromAttributes({
"appsignal.config.name": name,
"appsignal.config.environment": environment,
"appsignal.config.push_api_key": "0000-0000-0000-0000",
"appsignal.config.revision": revision,
"appsignal.config.language_integration": "node.js",
"appsignal.config.app_path": process.cwd(),
"host.name": os.hostname(),
[ATTR_SERVICE_NAME]: "My service name",
});
const sdk = new NodeSDK({
resource,
traceExporter: new OTLPTraceExporter({
url: `${endpoint}/v1/traces`,
}),
metricReader: new PeriodicExportingMetricReader({
exportIntervalMillis: 10000,
exporter: new OTLPMetricExporter({
url: `${endpoint}/v1/metrics`,
}),
}),
instrumentations: [getNodeAutoInstrumentations()],
});
sdk.start();