-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add anthropic receiver #202
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
Open
austinlparker
wants to merge
7
commits into
main
Choose a base branch
from
add-anthropic-receiver
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
fd0a9c1
Add AnthropicUsageReceiver component
austinlparker 5b2f2e7
Add AnthropicUsageReceiver component (development)
austinlparker 3fc647a
Add test data files for AnthropicUsageReceiver
austinlparker 5db498b
Update AnthropicUsageReceiver configuration to match implementation
austinlparker 8349c3c
Fix AnthropicUsageReceiver tests and remove optional filter fields fr…
austinlparker 99c7319
Rename collection_interval to usage_collection_interval for clarity
austinlparker ace80a7
Update config structure to match latest anthropic-usage-receiver changes
austinlparker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,216 @@ | ||
| kind: anthropicusage | ||
| name: Receive Anthropic Usage | ||
| style: receiver | ||
| logo: anthropic | ||
| type: base | ||
| status: development | ||
| version: v1 | ||
| summary: Collects usage metrics (via metrics) and cost data (via logs) from Anthropic API | ||
| description: | | ||
| The Anthropic Usage receiver collects detailed usage metrics and cost data from | ||
| the Anthropic Admin API, providing observability into your Claude API consumption. | ||
|
|
||
| This receiver periodically queries the Anthropic API and outputs data through | ||
| two different channels: | ||
|
|
||
| **Metrics channel**: | ||
| - Usage metrics: Token counts (input/output), API calls, grouped by model, | ||
| service tier, workspace, and API key | ||
|
|
||
| **Logs channel**: | ||
| - Cost data: Detailed spending information sent as structured usage logs, | ||
| aggregated by workspace and description | ||
|
|
||
| This dual-channel approach allows you to: | ||
| - Monitor API usage patterns and trends via metrics | ||
| - Track and analyze costs through usage logs | ||
| - Set up alerts for usage thresholds | ||
| - Implement chargeback or cost optimization workflows | ||
|
|
||
| Note: Requires an Anthropic Admin API key with appropriate permissions to | ||
| access usage and billing data. | ||
| tags: | ||
| - category:receiver | ||
| - service:collector | ||
| - signal:OTelMetrics | ||
| - signal:OTelLogs | ||
| - provider:anthropic | ||
| - telemetry:metrics | ||
| - telemetry:logs | ||
| - auth:admin_api_key | ||
| ports: | ||
| # outputs | ||
| - name: metrics | ||
| direction: output | ||
| type: OTelMetrics | ||
| - name: logs | ||
| direction: output | ||
| type: OTelLogs | ||
| properties: | ||
| - name: admin_api_key | ||
| summary: Anthropic admin API key for authentication | ||
| description: | | ||
| The admin API key from your Anthropic account. | ||
| This key is required to access usage and cost data. | ||
| type: string | ||
| validations: | ||
| - noblanks | ||
| default: ${env:ANTHROPIC_ADMIN_API_KEY} | ||
| required: true | ||
| - name: usage_collection_interval | ||
| summary: How often to collect usage metrics | ||
| description: | | ||
| The interval at which the receiver will query the Anthropic API | ||
| for usage metrics. Shorter intervals provide more real-time | ||
| data but may increase API usage. | ||
| type: duration | ||
| validations: | ||
| - noblanks | ||
| default: 1m | ||
| advanced: true | ||
| - name: usage_enabled | ||
| summary: Enable usage metrics collection | ||
| description: | | ||
| When enabled, collects detailed usage metrics including | ||
| token counts and API calls grouped by model and service tier. | ||
| type: bool | ||
| default: true | ||
| advanced: true | ||
| - name: usage_bucket_width | ||
| summary: Granularity for real-time usage metrics | ||
| description: | | ||
| The time bucket width for aggregating usage metrics. | ||
| Valid values are 1m, 1h, or 1d. | ||
| type: duration | ||
| validations: | ||
| - noblanks | ||
| default: 1m | ||
| advanced: true | ||
| - name: usage_lookback_window | ||
| summary: How far back to look for usage data on first run | ||
| description: | | ||
| On the first run, the receiver will look back this far | ||
| to collect historical usage data. | ||
| type: duration | ||
| validations: | ||
| - noblanks | ||
| default: 0s | ||
| advanced: true | ||
| - name: usage_group_by | ||
| summary: Fields to group usage metrics by | ||
| description: | | ||
| List of fields to use for grouping usage metrics. | ||
| Available fields: model, service_tier, workspace_id, api_key_id | ||
| type: stringarray | ||
| default: | ||
| - model | ||
| - service_tier | ||
| - workspace_id | ||
| - api_key_id | ||
| advanced: true | ||
| - name: models | ||
| summary: Filter metrics by specific models | ||
| description: | | ||
| List of model names to filter usage metrics. | ||
| Leave empty to collect metrics for all models. | ||
| type: stringarray | ||
| advanced: true | ||
| - name: service_tiers | ||
| summary: Filter metrics by service tiers | ||
| description: | | ||
| List of service tiers to filter usage metrics. | ||
| Valid values: standard, batch, priority. | ||
| Leave empty to collect metrics for all tiers. | ||
| type: stringarray | ||
| advanced: true | ||
| - name: workspace_ids | ||
| summary: Filter metrics by workspace IDs | ||
| description: | | ||
| List of workspace IDs to filter usage metrics. | ||
| Leave empty to collect metrics for all workspaces. | ||
| type: stringarray | ||
| advanced: true | ||
| - name: api_key_ids | ||
| summary: Filter metrics by API key IDs | ||
| description: | | ||
| List of API key IDs to filter usage metrics. | ||
| Leave empty to collect metrics for all API keys. | ||
| type: stringarray | ||
| advanced: true | ||
| - name: cost_enabled | ||
| summary: Enable cost metrics collection | ||
| description: | | ||
| When enabled, collects cost data from Anthropic billing API. | ||
| type: bool | ||
| default: true | ||
| advanced: true | ||
| - name: cost_bucket_width | ||
| summary: Time bucket width for cost aggregation | ||
| description: | | ||
| The granularity for cost data aggregation. | ||
| Daily aggregation is recommended for cost data. | ||
| type: duration | ||
| validations: | ||
| - noblanks | ||
| default: 1d | ||
| advanced: true | ||
| - name: cost_lookback_window | ||
| summary: How far back to look for cost data | ||
| description: | | ||
| The receiver will look back this far to collect historical cost data. | ||
| type: duration | ||
| validations: | ||
| - noblanks | ||
| default: 7d | ||
| advanced: true | ||
| - name: cost_collection_interval | ||
| summary: How often to check for new cost data | ||
| description: | | ||
| Cost data is typically updated less frequently than usage data, | ||
| so a longer interval is recommended. | ||
| type: duration | ||
| validations: | ||
| - noblanks | ||
| default: 24h | ||
| advanced: true | ||
| - name: cost_group_by | ||
| summary: Fields to group cost metrics by | ||
| description: | | ||
| List of fields to use for grouping cost metrics. | ||
| Available fields: workspace_id, description | ||
| type: stringarray | ||
| default: | ||
| - workspace_id | ||
| - description | ||
| advanced: true | ||
| templates: | ||
| - kind: collector_config | ||
| name: anthropicusage_receiver_collector | ||
| format: collector | ||
| meta: | ||
| componentSection: receivers | ||
| signalTypes: [metrics, logs] | ||
| collectorComponentName: anthropicusage | ||
| data: | ||
| - key: "{{ .ComponentName }}.admin_api_key" | ||
| value: "{{ .Values.admin_api_key }}" | ||
| - key: "{{ .ComponentName }}.usage.enabled" | ||
| value: "{{ .Values.usage_enabled | encodeAsBool }}" | ||
| - key: "{{ .ComponentName }}.usage.collection_interval" | ||
| value: "{{ .Values.usage_collection_interval }}" | ||
| - key: "{{ .ComponentName }}.usage.bucket_width" | ||
| value: "{{ .Values.usage_bucket_width }}" | ||
| - key: "{{ .ComponentName }}.usage.lookback_window" | ||
| value: "{{ .Values.usage_lookback_window }}" | ||
| - key: "{{ .ComponentName }}.usage.group_by" | ||
| value: "{{ .Values.usage_group_by | encodeAsArray }}" | ||
| - key: "{{ .ComponentName }}.cost.enabled" | ||
| value: "{{ .Values.cost_enabled | encodeAsBool }}" | ||
| - key: "{{ .ComponentName }}.cost.bucket_width" | ||
| value: "{{ .Values.cost_bucket_width }}" | ||
| - key: "{{ .ComponentName }}.cost.lookback_window" | ||
| value: "{{ .Values.cost_lookback_window }}" | ||
| - key: "{{ .ComponentName }}.cost.collection_interval" | ||
| value: "{{ .Values.cost_collection_interval }}" | ||
| - key: "{{ .ComponentName }}.cost.group_by" | ||
| value: "{{ .Values.cost_group_by | encodeAsArray }}" | ||
54 changes: 54 additions & 0 deletions
54
pkg/translator/testdata/collector_config/anthropicusage_all.yaml
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you manually test this config in a collector to confirm it works? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| receivers: | ||
| anthropicusage/anthropic_in: | ||
| admin_api_key: sk-ant-admin-test-key | ||
| cost: | ||
| bucket_width: 7d | ||
| collection_interval: 1h | ||
| enabled: true | ||
| group_by: | ||
| - workspace_id | ||
| lookback_window: 30d | ||
| usage: | ||
| bucket_width: 5m | ||
| collection_interval: 5m | ||
| enabled: true | ||
| group_by: | ||
| - model | ||
| - api_key_id | ||
| lookback_window: 1h | ||
| processors: | ||
| usage: {} | ||
| exporters: | ||
| otlphttp/logs_out: | ||
| endpoint: https://api.honeycomb.io:443 | ||
| sending_queue: | ||
| batch: | ||
| flush_timeout: 200ms | ||
| max_size: 8192 | ||
| min_size: 8192 | ||
| enabled: true | ||
| queue_size: 100000 | ||
| sizer: items | ||
| otlphttp/metrics_out: | ||
| endpoint: https://api.honeycomb.io:443 | ||
| sending_queue: | ||
| batch: | ||
| flush_timeout: 200ms | ||
| max_size: 8192 | ||
| min_size: 8192 | ||
| enabled: true | ||
| queue_size: 100000 | ||
| sizer: items | ||
| extensions: | ||
| honeycomb: {} | ||
| service: | ||
| extensions: [honeycomb] | ||
| pipelines: | ||
| logs/b6c-ce2: | ||
| receivers: [anthropicusage/anthropic_in] | ||
| processors: [usage] | ||
| exporters: [otlphttp/logs_out] | ||
| metrics/5b4-e88: | ||
| receivers: [anthropicusage/anthropic_in] | ||
| processors: [usage] | ||
| exporters: [otlphttp/metrics_out] |
57 changes: 57 additions & 0 deletions
57
pkg/translator/testdata/collector_config/anthropicusage_defaults.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| receivers: | ||
| anthropicusage/anthropic_in: | ||
| admin_api_key: ${env:ANTHROPIC_ADMIN_API_KEY} | ||
| cost: | ||
| bucket_width: 1d | ||
| collection_interval: 24h | ||
| enabled: true | ||
| group_by: | ||
| - workspace_id | ||
| - description | ||
| lookback_window: 7d | ||
| usage: | ||
| bucket_width: 1m | ||
| collection_interval: 1m | ||
| enabled: true | ||
| group_by: | ||
| - model | ||
| - service_tier | ||
| - workspace_id | ||
| - api_key_id | ||
| lookback_window: 0s | ||
| processors: | ||
| usage: {} | ||
| exporters: | ||
| otlphttp/logs_out: | ||
| endpoint: https://api.honeycomb.io:443 | ||
| sending_queue: | ||
| batch: | ||
| flush_timeout: 200ms | ||
| max_size: 8192 | ||
| min_size: 8192 | ||
| enabled: true | ||
| queue_size: 100000 | ||
| sizer: items | ||
| otlphttp/metrics_out: | ||
| endpoint: https://api.honeycomb.io:443 | ||
| sending_queue: | ||
| batch: | ||
| flush_timeout: 200ms | ||
| max_size: 8192 | ||
| min_size: 8192 | ||
| enabled: true | ||
| queue_size: 100000 | ||
| sizer: items | ||
| extensions: | ||
| honeycomb: {} | ||
| service: | ||
| extensions: [honeycomb] | ||
| pipelines: | ||
| logs/b6c-ce2: | ||
| receivers: [anthropicusage/anthropic_in] | ||
| processors: [usage] | ||
| exporters: [otlphttp/logs_out] | ||
| metrics/5b4-e88: | ||
| receivers: [anthropicusage/anthropic_in] | ||
| processors: [usage] | ||
| exporters: [otlphttp/metrics_out] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| components: | ||
| - name: anthropic_in | ||
| kind: anthropicusage | ||
| properties: | ||
| - name: admin_api_key | ||
| value: sk-ant-admin-test-key | ||
| - name: usage_collection_interval | ||
| value: 5m | ||
| - name: usage_enabled | ||
| value: false | ||
| - name: usage_bucket_width | ||
| value: 5m | ||
| - name: usage_lookback_window | ||
| value: 1h | ||
| - name: usage_group_by | ||
| value: | ||
| - model | ||
| - api_key_id | ||
| - name: cost_enabled | ||
| value: false | ||
| - name: cost_bucket_width | ||
| value: 7d | ||
| - name: cost_lookback_window | ||
| value: 30d | ||
| - name: cost_collection_interval | ||
| value: 1h | ||
| - name: cost_group_by | ||
| value: | ||
| - workspace_id | ||
| - name: metrics_out | ||
| kind: OTelHTTPExporter | ||
| - name: logs_out | ||
| kind: OTelHTTPExporter | ||
| connections: | ||
| - source: | ||
| component: anthropic_in | ||
| port: metrics | ||
| type: OTelMetrics | ||
| destination: | ||
| component: metrics_out | ||
| port: Metrics | ||
| type: OTelMetrics | ||
| - source: | ||
| component: anthropic_in | ||
| port: logs | ||
| type: OTelLogs | ||
| destination: | ||
| component: logs_out | ||
| port: Logs | ||
| type: OTelLogs |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.