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

Function getMetadata to get variables container.id and host.name that have already been defined inside agent #4449

Open
sefiros1 opened this issue Feb 3, 2025 · 0 comments

Comments

@sefiros1
Copy link
Contributor

sefiros1 commented Feb 3, 2025

Is your feature request related to a problem? Please describe.
I need to get metadata container.id and/or host.name from APM Agent for my logger lib to link my logs with service in Kibana UI.
I've already added ...apmAgent.currentTraceIds() in logs, but not works as intended. For example, container.id or host.name required for logs to be shown in Logs tab in Kibana (thread).

I not have access or opportunity to add these variables in filebeat or something else outside of node application. My solutions will be dictated by this limitation.

Describe the solution you'd like
I suggest to create function apmAgent.getMetadata(), that will return object like this:

{
  service: {
    name: 'localtest',
    environment: 'develop',
    runtime: { name: 'node', version: '20.15.1' },
    language: { name: 'javascript' },
    agent: { name: 'nodejs', version: '4.11.0', activation_method: 'require' },
    framework: undefined,
    version: '5.0.0',
    node: undefined
  },
  process: {
    pid: 1160,
    ppid: 1,
    title: 'node',
    argv: [ '/usr/local/bin/ts-node', '/app/lib/apm-agent.ts' ]
  },
  system: {
    architecture: 'x64',
    platform: 'linux',
    container: { id: 'some-container-id' },
    kubernetes: undefined,
    detected_hostname: '54e8d5b15c0d'
  }
}

It can be stored and updated in http-apm-client and proxied through Agent.

Describe alternatives you've considered
As temporary working solution, I ended up with using addMetadataFilter function like this:

public async getMetadata(apmAgent: Agent) {
	return new Promise<Payload>(resolve => {
		apmAgent.addMetadataFilter((payload) => {
			resolve(payload);
			return payload;
		});
	});
}

As far as I know, this filter should be invoked immediately after adding if agent is started. But still looks like bad solution in my opinion, because multiple calls will increase filter array and execution ticks for process these filters (memory leak opportunity).

Additional context

I repeat, that I do not have access or opportunity to add these variables in filebeat or something else outside of node application, I will appreciate solution in NodeJS application.

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

No branches or pull requests

1 participant