From c25443d8a480c5107864b21de3420638131eef67 Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Mon, 22 Apr 2024 09:10:29 -0400 Subject: [PATCH] [8.14] fix otel service detection (#180574) (#181298) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Backport This will backport the following commits from `main` to `8.14`: - [fix otel service detection (#180574)](https://github.com/elastic/kibana/pull/180574) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: SylvainJuge <763082+SylvainJuge@users.noreply.github.com> --- .../kbn-elastic-agent-utils/src/agent_guards.test.ts | 6 ++++++ packages/kbn-elastic-agent-utils/src/agent_guards.ts | 10 ++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/kbn-elastic-agent-utils/src/agent_guards.test.ts b/packages/kbn-elastic-agent-utils/src/agent_guards.test.ts index 0de2ea225ce81..aa55aa94b16ca 100644 --- a/packages/kbn-elastic-agent-utils/src/agent_guards.test.ts +++ b/packages/kbn-elastic-agent-utils/src/agent_guards.test.ts @@ -23,11 +23,17 @@ import { describe('Agents guards', () => { it('isOpenTelemetryAgentName should guard if the passed agent is an OpenTelemetry one.', () => { expect(isOpenTelemetryAgentName('otlp')).toBe(true); + expect(isOpenTelemetryAgentName('opentelemetry/java')).toBe(true); + expect(isOpenTelemetryAgentName('opentelemetry/java/opentelemetry-java-instrumentation')).toBe( + true + ); expect(isOpenTelemetryAgentName('not-an-agent')).toBe(false); }); it('isJavaAgentName should guard if the passed agent is an Java one.', () => { expect(isJavaAgentName('java')).toBe(true); + expect(isJavaAgentName('opentelemetry/java')).toBe(true); + expect(isJavaAgentName('opentelemetry/java/opentelemetry-java-instrumentation')).toBe(true); expect(isJavaAgentName('not-an-agent')).toBe(false); }); diff --git a/packages/kbn-elastic-agent-utils/src/agent_guards.ts b/packages/kbn-elastic-agent-utils/src/agent_guards.ts index 6997cbd81c42c..43cf4cce89f4a 100644 --- a/packages/kbn-elastic-agent-utils/src/agent_guards.ts +++ b/packages/kbn-elastic-agent-utils/src/agent_guards.ts @@ -16,11 +16,17 @@ import type { } from './agent_names'; export function isOpenTelemetryAgentName(agentName: string): agentName is OpenTelemetryAgentName { - return OPEN_TELEMETRY_AGENT_NAMES.includes(agentName as OpenTelemetryAgentName); + return ( + agentName?.startsWith('opentelemetry/') || + OPEN_TELEMETRY_AGENT_NAMES.includes(agentName as OpenTelemetryAgentName) + ); } export function isJavaAgentName(agentName?: string): agentName is JavaAgentName { - return JAVA_AGENT_NAMES.includes(agentName! as JavaAgentName); + return ( + agentName?.startsWith('opentelemetry/java') || + JAVA_AGENT_NAMES.includes(agentName! as JavaAgentName) + ); } export function isRumAgentName(agentName?: string): agentName is RumAgentName {