Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logging to Elastic Agent and logs are showing in unknown_service_node instead of services #4689

Closed
1 of 2 tasks
dileep9490 opened this issue May 9, 2024 · 1 comment
Closed
1 of 2 tasks

Comments

@dileep9490
Copy link

dileep9490 commented May 9, 2024

  • This only affects the JavaScript OpenTelemetry library
  • This may affect other libraries, but I would like to get opinions here first

I'm working with nodeSDK and pushing the data to otel-collector which will push the data to elastic agent

this is my tracker.js file

import { NodeSDK } from "@opentelemetry/sdk-node";
import { getNodeAutoInstrumentations } from "@opentelemetry/auto-instrumentations-node";
import { OTLPLogExporter } from "@opentelemetry/exporter-logs-otlp-http";
import {
	LoggerProvider,
	BatchLogRecordProcessor,
} from "@opentelemetry/sdk-logs";
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
import { OTLPMetricExporter } from "@opentelemetry/exporter-metrics-otlp-http";
import { PeriodicExportingMetricReader } from "@opentelemetry/sdk-metrics";

const traceExporter = new OTLPTraceExporter({
	url: "http://localhost:4318/v1/traces",
});

const metricExporter = new OTLPMetricExporter({
	url: "http://localhost:4318/v1/metrics",
});

const sdk = new NodeSDK({
	serviceName: "App 1",
	traceExporter: traceExporter,
	metricReader: new PeriodicExportingMetricReader({
		exporter: metricExporter,
	}),
	instrumentations: [getNodeAutoInstrumentations()],
});

sdk.start();

const logExporter = new OTLPLogExporter({
	url: "http://localhost:4318/v1/logs",
});
const loggerProvider = new LoggerProvider({});

loggerProvider.addLogRecordProcessor(new BatchLogRecordProcessor(logExporter));

const logger = loggerProvider.getLogger("default", "1.0.0");

export { logger };

I have 2 apps pushing to one collector and then it pushes to single elastic agent. When metrics are pushed I can see them in their appropriate services but logs are being pushed to unknow_service_node service. I want the logs in their respective services how can i do that?

@dileep9490
Copy link
Author

Found the solution:

By create a resource like this:

import { SEMRESATTRS_SERVICE_NAME } from "@opentelemetry/semantic-conventions";

const resource = Resource.default().merge(
	new Resource({
		[SEMRESATTRS_SERVICE_NAME]: "App 1",
	})
);

passing this to my loggers and Nodesdk worked

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant