From 9ac9172fd38b1ae5ba919f33cfb262f5678777cc Mon Sep 17 00:00:00 2001 From: Sam Brenner Date: Tue, 29 Oct 2024 10:09:00 -0400 Subject: [PATCH] address review comments --- packages/dd-trace/src/llmobs/channels.js | 10 ---------- .../llmobs/{constants.js => constants/tags.js} | 18 +++--------------- packages/dd-trace/src/llmobs/constants/text.js | 6 ++++++ .../dd-trace/src/llmobs/constants/writers.js | 13 +++++++++++++ packages/dd-trace/src/llmobs/index.js | 14 +++++++------- packages/dd-trace/src/llmobs/sdk.js | 6 ++++-- packages/dd-trace/src/llmobs/span_processor.js | 6 +++--- packages/dd-trace/src/llmobs/tagger.js | 2 +- packages/dd-trace/src/llmobs/util.js | 2 +- .../dd-trace/src/llmobs/writers/evaluations.js | 2 +- .../src/llmobs/writers/spans/agentProxy.js | 6 +++++- .../src/llmobs/writers/spans/agentless.js | 2 +- .../dd-trace/src/llmobs/writers/spans/base.js | 9 +++------ packages/dd-trace/test/llmobs/index.spec.js | 13 +++++++------ 14 files changed, 55 insertions(+), 54 deletions(-) delete mode 100644 packages/dd-trace/src/llmobs/channels.js rename packages/dd-trace/src/llmobs/{constants.js => constants/tags.js} (59%) create mode 100644 packages/dd-trace/src/llmobs/constants/text.js create mode 100644 packages/dd-trace/src/llmobs/constants/writers.js diff --git a/packages/dd-trace/src/llmobs/channels.js b/packages/dd-trace/src/llmobs/channels.js deleted file mode 100644 index bada1e28190..00000000000 --- a/packages/dd-trace/src/llmobs/channels.js +++ /dev/null @@ -1,10 +0,0 @@ -'use strict' - -const { channel } = require('dc-polyfill') - -module.exports = { - injectCh: channel('dd-trace:span:inject'), - spanProcessCh: channel('dd-trace:span:process'), - evalMetricAppendCh: channel('llmobs:eval-metric:append'), - flushCh: channel('llmobs:writers:flush') -} diff --git a/packages/dd-trace/src/llmobs/constants.js b/packages/dd-trace/src/llmobs/constants/tags.js similarity index 59% rename from packages/dd-trace/src/llmobs/constants.js rename to packages/dd-trace/src/llmobs/constants/tags.js index 411ac1c3f05..eee9a6b9890 100644 --- a/packages/dd-trace/src/llmobs/constants.js +++ b/packages/dd-trace/src/llmobs/constants/tags.js @@ -26,21 +26,9 @@ module.exports = { OUTPUT_MESSAGES: '_ml_obs.meta.output.messages', OUTPUT_VALUE: '_ml_obs.meta.output.value', - EVP_PROXY_AGENT_BASE_PATH: 'evp_proxy/v2', - EVP_PROXY_AGENT_ENDPOINT: 'evp_proxy/v2/api/v2/llmobs', - EVP_SUBDOMAIN_HEADER_NAME: 'X-Datadog-EVP-Subdomain', - EVP_SUBDOMAIN_HEADER_VALUE: 'llmobs-intake', - AGENTLESS_SPANS_ENDPOINT: '/api/v2/llmobs', - AGENTLESS_EVALULATIONS_ENDPOINT: '/api/intake/llm-obs/v1/eval-metric', - - EVP_PAYLOAD_SIZE_LIMIT: 5 << 20, // 5MB (actual limit is 5.1MB) - EVP_EVENT_SIZE_LIMIT: (1 << 20) - 1024, // 999KB (actual limit is 1MB) - - DROPPED_IO_COLLECTION_ERROR: 'dropped_io', - DROPPED_VALUE_TEXT: "[This value has been dropped because this span's size exceeds the 1MB size limit.]", - UNSERIALIZABLE_VALUE_TEXT: 'Unserializable value', - INPUT_TOKENS_METRIC_KEY: 'input_tokens', OUTPUT_TOKENS_METRIC_KEY: 'output_tokens', - TOTAL_TOKENS_METRIC_KEY: 'total_tokens' + TOTAL_TOKENS_METRIC_KEY: 'total_tokens', + + DROPPED_IO_COLLECTION_ERROR: 'dropped_io' } diff --git a/packages/dd-trace/src/llmobs/constants/text.js b/packages/dd-trace/src/llmobs/constants/text.js new file mode 100644 index 00000000000..3c19b9febb6 --- /dev/null +++ b/packages/dd-trace/src/llmobs/constants/text.js @@ -0,0 +1,6 @@ +'use strict' + +module.exports = { + DROPPED_VALUE_TEXT: "[This value has been dropped because this span's size exceeds the 1MB size limit.]", + UNSERIALIZABLE_VALUE_TEXT: 'Unserializable value' +} diff --git a/packages/dd-trace/src/llmobs/constants/writers.js b/packages/dd-trace/src/llmobs/constants/writers.js new file mode 100644 index 00000000000..3726c33c7c0 --- /dev/null +++ b/packages/dd-trace/src/llmobs/constants/writers.js @@ -0,0 +1,13 @@ +'use strict' + +module.exports = { + EVP_PROXY_AGENT_BASE_PATH: 'evp_proxy/v2', + EVP_PROXY_AGENT_ENDPOINT: 'evp_proxy/v2/api/v2/llmobs', + EVP_SUBDOMAIN_HEADER_NAME: 'X-Datadog-EVP-Subdomain', + EVP_SUBDOMAIN_HEADER_VALUE: 'llmobs-intake', + AGENTLESS_SPANS_ENDPOINT: '/api/v2/llmobs', + AGENTLESS_EVALULATIONS_ENDPOINT: '/api/intake/llm-obs/v1/eval-metric', + + EVP_PAYLOAD_SIZE_LIMIT: 5 << 20, // 5MB (actual limit is 5.1MB) + EVP_EVENT_SIZE_LIMIT: (1 << 20) - 1024 // 999KB (actual limit is 1MB) +} diff --git a/packages/dd-trace/src/llmobs/index.js b/packages/dd-trace/src/llmobs/index.js index 42b6ffa5dd8..1b287aeb432 100644 --- a/packages/dd-trace/src/llmobs/index.js +++ b/packages/dd-trace/src/llmobs/index.js @@ -1,17 +1,17 @@ 'use strict' const log = require('../log') -const { PROPAGATED_PARENT_ID_KEY } = require('./constants') +const { PROPAGATED_PARENT_ID_KEY } = require('./constants/tags') const { storage } = require('../../../datadog-core') const LLMObsSpanProcessor = require('./span_processor') -const { - injectCh, - spanProcessCh, - evalMetricAppendCh, - flushCh -} = require('./channels') +const { channel } = require('dc-polyfill') +const spanProcessCh = channel('dd-trace:span:process') +const evalMetricAppendCh = channel('llmobs:eval-metric:append') +const flushCh = channel('llmobs:writers:flush') +const injectCh = channel('dd-trace:span:inject') + const LLMObsAgentlessSpanWriter = require('./writers/spans/agentless') const LLMObsAgentProxySpanWriter = require('./writers/spans/agentProxy') const LLMObsEvalMetricsWriter = require('./writers/evaluations') diff --git a/packages/dd-trace/src/llmobs/sdk.js b/packages/dd-trace/src/llmobs/sdk.js index 260628bb754..3a6363245d3 100644 --- a/packages/dd-trace/src/llmobs/sdk.js +++ b/packages/dd-trace/src/llmobs/sdk.js @@ -1,6 +1,6 @@ 'use strict' -const { SPAN_KIND, OUTPUT_VALUE } = require('./constants') +const { SPAN_KIND, OUTPUT_VALUE } = require('./constants/tags') const { getFunctionArguments, @@ -19,7 +19,9 @@ const logger = require('../log') const LLMObsTagger = require('./tagger') // communicating with writer -const { flushCh, evalMetricAppendCh } = require('./channels') +const { channel } = require('dc-polyfill') +const evalMetricAppendCh = channel('llmobs:eval-metric:append') +const flushCh = channel('llmobs:writers:flush') const NoopLLMObs = require('./noop') class LLMObs extends NoopLLMObs { diff --git a/packages/dd-trace/src/llmobs/span_processor.js b/packages/dd-trace/src/llmobs/span_processor.js index d72a8c6fe1b..bc8eeda06b7 100644 --- a/packages/dd-trace/src/llmobs/span_processor.js +++ b/packages/dd-trace/src/llmobs/span_processor.js @@ -16,9 +16,9 @@ const { TAGS, PARENT_ID_KEY, SESSION_ID, - NAME, - UNSERIALIZABLE_VALUE_TEXT -} = require('./constants') + NAME +} = require('./constants/tags') +const { UNSERIALIZABLE_VALUE_TEXT } = require('./constants/text') const { ERROR_MESSAGE, diff --git a/packages/dd-trace/src/llmobs/tagger.js b/packages/dd-trace/src/llmobs/tagger.js index b0ae13cf5f9..9f1728e5d7b 100644 --- a/packages/dd-trace/src/llmobs/tagger.js +++ b/packages/dd-trace/src/llmobs/tagger.js @@ -23,7 +23,7 @@ const { INPUT_TOKENS_METRIC_KEY, OUTPUT_TOKENS_METRIC_KEY, TOTAL_TOKENS_METRIC_KEY -} = require('./constants') +} = require('./constants/tags') // global registry of LLMObs spans // maps LLMObs spans to their annotations diff --git a/packages/dd-trace/src/llmobs/util.js b/packages/dd-trace/src/llmobs/util.js index 12c9fc6664c..feba656f952 100644 --- a/packages/dd-trace/src/llmobs/util.js +++ b/packages/dd-trace/src/llmobs/util.js @@ -1,6 +1,6 @@ 'use strict' -const { SPAN_KINDS } = require('./constants') +const { SPAN_KINDS } = require('./constants/tags') function encodeUnicode (str) { if (!str) return str diff --git a/packages/dd-trace/src/llmobs/writers/evaluations.js b/packages/dd-trace/src/llmobs/writers/evaluations.js index 74a26b4b1c0..01d9beac33b 100644 --- a/packages/dd-trace/src/llmobs/writers/evaluations.js +++ b/packages/dd-trace/src/llmobs/writers/evaluations.js @@ -1,6 +1,6 @@ 'use strict' -const { AGENTLESS_EVALULATIONS_ENDPOINT } = require('../constants') +const { AGENTLESS_EVALULATIONS_ENDPOINT } = require('../constants/writers') const BaseWriter = require('./base') class LLMObsEvalMetricsWriter extends BaseWriter { diff --git a/packages/dd-trace/src/llmobs/writers/spans/agentProxy.js b/packages/dd-trace/src/llmobs/writers/spans/agentProxy.js index 41686c94ba1..6274f6117e0 100644 --- a/packages/dd-trace/src/llmobs/writers/spans/agentProxy.js +++ b/packages/dd-trace/src/llmobs/writers/spans/agentProxy.js @@ -1,6 +1,10 @@ 'use strict' -const { EVP_SUBDOMAIN_HEADER_NAME, EVP_SUBDOMAIN_HEADER_VALUE, EVP_PROXY_AGENT_ENDPOINT } = require('../../constants') +const { + EVP_SUBDOMAIN_HEADER_NAME, + EVP_SUBDOMAIN_HEADER_VALUE, + EVP_PROXY_AGENT_ENDPOINT +} = require('../../constants/writers') const LLMObsBaseSpanWriter = require('./base') class LLMObsAgentProxySpanWriter extends LLMObsBaseSpanWriter { diff --git a/packages/dd-trace/src/llmobs/writers/spans/agentless.js b/packages/dd-trace/src/llmobs/writers/spans/agentless.js index 95286b8e02a..7391acacefb 100644 --- a/packages/dd-trace/src/llmobs/writers/spans/agentless.js +++ b/packages/dd-trace/src/llmobs/writers/spans/agentless.js @@ -1,6 +1,6 @@ 'use strict' -const { AGENTLESS_SPANS_ENDPOINT } = require('../../constants') +const { AGENTLESS_SPANS_ENDPOINT } = require('../../constants/writers') const LLMObsBaseSpanWriter = require('./base') class LLMObsAgentlessSpanWriter extends LLMObsBaseSpanWriter { diff --git a/packages/dd-trace/src/llmobs/writers/spans/base.js b/packages/dd-trace/src/llmobs/writers/spans/base.js index 743769eeef1..f5fe3443f2d 100644 --- a/packages/dd-trace/src/llmobs/writers/spans/base.js +++ b/packages/dd-trace/src/llmobs/writers/spans/base.js @@ -1,11 +1,8 @@ 'use strict' -const { - EVP_EVENT_SIZE_LIMIT, - EVP_PAYLOAD_SIZE_LIMIT, - DROPPED_VALUE_TEXT, - DROPPED_IO_COLLECTION_ERROR -} = require('../../constants') +const { EVP_EVENT_SIZE_LIMIT, EVP_PAYLOAD_SIZE_LIMIT } = require('../../constants/writers') +const { DROPPED_VALUE_TEXT } = require('../../constants/text') +const { DROPPED_IO_COLLECTION_ERROR } = require('../../constants/tags') const BaseWriter = require('../base') const logger = require('../../../log') diff --git a/packages/dd-trace/test/llmobs/index.spec.js b/packages/dd-trace/test/llmobs/index.spec.js index 611b927e0ec..8564a9c1629 100644 --- a/packages/dd-trace/test/llmobs/index.spec.js +++ b/packages/dd-trace/test/llmobs/index.spec.js @@ -1,12 +1,13 @@ 'use strict' const proxyquire = require('proxyquire') -const { - injectCh, - evalMetricAppendCh, - spanProcessCh, - flushCh -} = require('../../src/llmobs/channels') + +const { channel } = require('dc-polyfill') +const spanProcessCh = channel('dd-trace:span:process') +const evalMetricAppendCh = channel('llmobs:eval-metric:append') +const flushCh = channel('llmobs:writers:flush') +const injectCh = channel('dd-trace:span:inject') + const LLMObsEvalMetricsWriter = require('../../src/llmobs/writers/evaluations') const config = {