Commit graph

1 commit

Author SHA1 Message Date
Dario Gieselaar
6d0e4b8d28
[8.19] [Inference] Instrument inference with OpenTelemetry (#218694) (#220349)
# Backport

This will backport the following commits from `main` to `8.19`:
- [[Inference] Instrument inference with OpenTelemetry
(#218694)](https://github.com/elastic/kibana/pull/218694)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Dario
Gieselaar","email":"dario.gieselaar@elastic.co"},"sourceCommit":{"committedDate":"2025-05-07T09:44:29Z","message":"[Inference]
Instrument inference with OpenTelemetry (#218694)\n\nInstrument the
inference chatComplete API with OpenTelemetry, and export\nhelper
functions to create spans w/ the right semconv
attributes.\nAdditionally, optionally export to Langfuse or
Phoenix.\n\n## Centralizes OpenTelemetry setup\n\nAs this is the first
instance of OpenTelemetry based _tracing_ (we\nalready have metrics in
the MonitoringCollection plugin), some\nbootstrapping code is necessary
to centrally configure OpenTelemetry. To\nthis end, I've added the
following config settings:\n\n- `telemetry.tracing.enabled`: whether
OpenTelemetry tracing is enabled\n(defaults to undefined, if undefined,
falls back to `telemetry.enabled`)\n- `telemetry.tracing.sample_rate`
(defaults to 1)\n\nThe naming of these configuration settings is mostly
in-line with [the\nElasticsearch
tracing\nsettings](https://github.com/elastic/elasticsearch/blob/main/TRACING.md).\n\nThe
following packages (containing bootstrapping logic, utility\nfunctions,
types and config schemas) were added:\n- `@kbn/telemetry`\n-
`@kbn/telemetry-config` \n- `@kbn/tracing`\n\nThe OpenTelemetry
bootstrapping depends on @kbn/apm-config-loader, as it\nhas the same
constraints - it needs to run before any other code, and it\nneeds to
read the raw config.\n\nAdditionally, a root `telemetry` logger was
added that captures\nOpenTelemetry logs.\n\nNote that there is no
default exporter for spans, which means that\nalthough spans are being
recorded, they do not get exported.\n\n## Instrument chatComplete
calls\n\nCalls to `chatComplete` now create OpenTelemetry spans,
roughly\nfollowing semantic conventions (which for GenAI are very much
in flux).\nSome helper functions were added to create other inference
spans. These\nhelper functions use baggage to determine whether the
created inference\nspan is the \"root\" of an inference trace. This
allows us to export these\nspans as if it were root spans - something
that is needed to be able to\neasily visualize these in other
tools.\n\nLeveraging these inference spans, two exporters are added. One
for\n[Phoenix](https://github.com/Arize-ai/phoenix) and one
for\n[Langfuse](https://github.com/langfuse/langfuse/tree/main):
two\nopen-source LLM Observability suites. This allows engineers that
use the\nInference plugin to be able to inspect and improve their
LLM-based\nworkflows with much less effort.\n\nFor both Phoenix and
Langfuse, two service scripts were added. Run `node\nscripts/phoenix` or
`node scripts/langfuse` to get started. Both scripts\nwork with
zero-config - they will log generated Kibana config to
stdout.\n\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>\nCo-authored-by:
Elastic Machine
<elasticmachine@users.noreply.github.com>","sha":"2387e3b88c83317ddd5354dff751a1ac0fb62bb9","branchLabelMapping":{"^v9.1.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:Obs
AI
Assistant","ci:project-deploy-observability","backport:version","v9.1.0","v8.19.0"],"title":"[Inference]
Instrument inference with
OpenTelemetry","number":218694,"url":"https://github.com/elastic/kibana/pull/218694","mergeCommit":{"message":"[Inference]
Instrument inference with OpenTelemetry (#218694)\n\nInstrument the
inference chatComplete API with OpenTelemetry, and export\nhelper
functions to create spans w/ the right semconv
attributes.\nAdditionally, optionally export to Langfuse or
Phoenix.\n\n## Centralizes OpenTelemetry setup\n\nAs this is the first
instance of OpenTelemetry based _tracing_ (we\nalready have metrics in
the MonitoringCollection plugin), some\nbootstrapping code is necessary
to centrally configure OpenTelemetry. To\nthis end, I've added the
following config settings:\n\n- `telemetry.tracing.enabled`: whether
OpenTelemetry tracing is enabled\n(defaults to undefined, if undefined,
falls back to `telemetry.enabled`)\n- `telemetry.tracing.sample_rate`
(defaults to 1)\n\nThe naming of these configuration settings is mostly
in-line with [the\nElasticsearch
tracing\nsettings](https://github.com/elastic/elasticsearch/blob/main/TRACING.md).\n\nThe
following packages (containing bootstrapping logic, utility\nfunctions,
types and config schemas) were added:\n- `@kbn/telemetry`\n-
`@kbn/telemetry-config` \n- `@kbn/tracing`\n\nThe OpenTelemetry
bootstrapping depends on @kbn/apm-config-loader, as it\nhas the same
constraints - it needs to run before any other code, and it\nneeds to
read the raw config.\n\nAdditionally, a root `telemetry` logger was
added that captures\nOpenTelemetry logs.\n\nNote that there is no
default exporter for spans, which means that\nalthough spans are being
recorded, they do not get exported.\n\n## Instrument chatComplete
calls\n\nCalls to `chatComplete` now create OpenTelemetry spans,
roughly\nfollowing semantic conventions (which for GenAI are very much
in flux).\nSome helper functions were added to create other inference
spans. These\nhelper functions use baggage to determine whether the
created inference\nspan is the \"root\" of an inference trace. This
allows us to export these\nspans as if it were root spans - something
that is needed to be able to\neasily visualize these in other
tools.\n\nLeveraging these inference spans, two exporters are added. One
for\n[Phoenix](https://github.com/Arize-ai/phoenix) and one
for\n[Langfuse](https://github.com/langfuse/langfuse/tree/main):
two\nopen-source LLM Observability suites. This allows engineers that
use the\nInference plugin to be able to inspect and improve their
LLM-based\nworkflows with much less effort.\n\nFor both Phoenix and
Langfuse, two service scripts were added. Run `node\nscripts/phoenix` or
`node scripts/langfuse` to get started. Both scripts\nwork with
zero-config - they will log generated Kibana config to
stdout.\n\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>\nCo-authored-by:
Elastic Machine
<elasticmachine@users.noreply.github.com>","sha":"2387e3b88c83317ddd5354dff751a1ac0fb62bb9"}},"sourceBranch":"main","suggestedTargetBranches":["8.19"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/218694","number":218694,"mergeCommit":{"message":"[Inference]
Instrument inference with OpenTelemetry (#218694)\n\nInstrument the
inference chatComplete API with OpenTelemetry, and export\nhelper
functions to create spans w/ the right semconv
attributes.\nAdditionally, optionally export to Langfuse or
Phoenix.\n\n## Centralizes OpenTelemetry setup\n\nAs this is the first
instance of OpenTelemetry based _tracing_ (we\nalready have metrics in
the MonitoringCollection plugin), some\nbootstrapping code is necessary
to centrally configure OpenTelemetry. To\nthis end, I've added the
following config settings:\n\n- `telemetry.tracing.enabled`: whether
OpenTelemetry tracing is enabled\n(defaults to undefined, if undefined,
falls back to `telemetry.enabled`)\n- `telemetry.tracing.sample_rate`
(defaults to 1)\n\nThe naming of these configuration settings is mostly
in-line with [the\nElasticsearch
tracing\nsettings](https://github.com/elastic/elasticsearch/blob/main/TRACING.md).\n\nThe
following packages (containing bootstrapping logic, utility\nfunctions,
types and config schemas) were added:\n- `@kbn/telemetry`\n-
`@kbn/telemetry-config` \n- `@kbn/tracing`\n\nThe OpenTelemetry
bootstrapping depends on @kbn/apm-config-loader, as it\nhas the same
constraints - it needs to run before any other code, and it\nneeds to
read the raw config.\n\nAdditionally, a root `telemetry` logger was
added that captures\nOpenTelemetry logs.\n\nNote that there is no
default exporter for spans, which means that\nalthough spans are being
recorded, they do not get exported.\n\n## Instrument chatComplete
calls\n\nCalls to `chatComplete` now create OpenTelemetry spans,
roughly\nfollowing semantic conventions (which for GenAI are very much
in flux).\nSome helper functions were added to create other inference
spans. These\nhelper functions use baggage to determine whether the
created inference\nspan is the \"root\" of an inference trace. This
allows us to export these\nspans as if it were root spans - something
that is needed to be able to\neasily visualize these in other
tools.\n\nLeveraging these inference spans, two exporters are added. One
for\n[Phoenix](https://github.com/Arize-ai/phoenix) and one
for\n[Langfuse](https://github.com/langfuse/langfuse/tree/main):
two\nopen-source LLM Observability suites. This allows engineers that
use the\nInference plugin to be able to inspect and improve their
LLM-based\nworkflows with much less effort.\n\nFor both Phoenix and
Langfuse, two service scripts were added. Run `node\nscripts/phoenix` or
`node scripts/langfuse` to get started. Both scripts\nwork with
zero-config - they will log generated Kibana config to
stdout.\n\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>\nCo-authored-by:
Elastic Machine
<elasticmachine@users.noreply.github.com>","sha":"2387e3b88c83317ddd5354dff751a1ac0fb62bb9"}},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2025-05-09 07:35:24 -04:00