anthropic 1.78.0 → 1.79.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +35 -0
- data/LICENSE +8 -0
- data/README.md +42 -1
- data/lib/anthropic/client.rb +32 -0
- data/lib/anthropic/helpers/aws/client.rb +12 -2
- data/lib/anthropic/helpers/aws_auth.rb +8 -1
- data/lib/anthropic/helpers/bedrock/client.rb +19 -2
- data/lib/anthropic/helpers/bedrock/mantle_client.rb +19 -2
- data/lib/anthropic/helpers/google_cloud/client.rb +12 -2
- data/lib/anthropic/helpers/streaming/message_stream.rb +20 -43
- data/lib/anthropic/helpers/tools/runner.rb +104 -11
- data/lib/anthropic/helpers/tracing/attributes.rb +34 -0
- data/lib/anthropic/helpers/tracing/config.rb +16 -0
- data/lib/anthropic/helpers/tracing/content.rb +346 -0
- data/lib/anthropic/helpers/tracing/recorders.rb +131 -0
- data/lib/anthropic/helpers/tracing/response.rb +29 -0
- data/lib/anthropic/helpers/tracing/streamed_message.rb +189 -0
- data/lib/anthropic/helpers/tracing/tool_spans.rb +138 -0
- data/lib/anthropic/helpers/tracing.rb +13 -0
- data/lib/anthropic/helpers/vertex/client.rb +19 -2
- data/lib/anthropic/internal/tracing.rb +1118 -0
- data/lib/anthropic/internal/transport/base_client.rb +174 -10
- data/lib/anthropic/internal/transport/pooled_net_requester.rb +6 -0
- data/lib/anthropic/models/anthropic_beta.rb +3 -0
- data/lib/anthropic/models/beta/agent_create_params.rb +17 -6
- data/lib/anthropic/models/beta/agent_update_params.rb +17 -6
- data/lib/anthropic/models/beta/beta_dream_input.rb +2 -2
- data/lib/anthropic/models/beta/beta_fallbacks_param.rb +6 -2
- data/lib/anthropic/models/beta/beta_managed_agents_agent.rb +15 -6
- data/lib/anthropic/models/beta/beta_managed_agents_agent_tool_config_params.rb +8 -8
- data/lib/anthropic/models/beta/beta_managed_agents_agent_toolset_default_config.rb +2 -2
- data/lib/anthropic/models/beta/beta_managed_agents_agent_toolset_default_config_params.rb +2 -2
- data/lib/anthropic/models/beta/beta_managed_agents_agent_with_overrides_params.rb +6 -6
- data/lib/anthropic/models/beta/beta_managed_agents_aws_role_execution_identity.rb +29 -0
- data/lib/anthropic/models/beta/beta_managed_agents_aws_role_execution_identity_params.rb +34 -0
- data/lib/anthropic/models/beta/beta_managed_agents_bash_tool_config.rb +2 -2
- data/lib/anthropic/models/beta/beta_managed_agents_bash_tool_config_params.rb +2 -2
- data/lib/anthropic/models/beta/beta_managed_agents_deployment_initial_event.rb +3 -3
- data/lib/anthropic/models/beta/beta_managed_agents_deployment_initial_event_params.rb +3 -3
- data/lib/anthropic/models/beta/beta_managed_agents_deployment_paused_reason.rb +2 -2
- data/lib/anthropic/models/beta/beta_managed_agents_deployment_paused_reason_error.rb +38 -14
- data/lib/anthropic/models/beta/beta_managed_agents_deployment_run.rb +16 -16
- data/lib/anthropic/models/beta/beta_managed_agents_deployment_user_define_outcome_event.rb +2 -2
- data/lib/anthropic/models/beta/beta_managed_agents_deployment_user_message_event.rb +4 -4
- data/lib/anthropic/models/beta/beta_managed_agents_edit_tool_config.rb +2 -2
- data/lib/anthropic/models/beta/beta_managed_agents_edit_tool_config_params.rb +2 -2
- data/lib/anthropic/models/beta/beta_managed_agents_execution_identity.rb +57 -0
- data/lib/anthropic/models/beta/beta_managed_agents_execution_identity_params.rb +62 -0
- data/lib/anthropic/models/beta/beta_managed_agents_github_repository_resource_config.rb +2 -2
- data/lib/anthropic/models/beta/beta_managed_agents_github_repository_resource_params.rb +2 -2
- data/lib/anthropic/models/beta/beta_managed_agents_glob_tool_config.rb +2 -2
- data/lib/anthropic/models/beta/beta_managed_agents_glob_tool_config_params.rb +2 -2
- data/lib/anthropic/models/beta/beta_managed_agents_grep_tool_config.rb +2 -2
- data/lib/anthropic/models/beta/beta_managed_agents_grep_tool_config_params.rb +2 -2
- data/lib/anthropic/models/beta/beta_managed_agents_mcp_tool_config.rb +2 -2
- data/lib/anthropic/models/beta/beta_managed_agents_mcp_tool_config_params.rb +2 -2
- data/lib/anthropic/models/beta/beta_managed_agents_mcp_toolset_default_config.rb +2 -2
- data/lib/anthropic/models/beta/beta_managed_agents_mcp_toolset_default_config_params.rb +2 -2
- data/lib/anthropic/models/beta/beta_managed_agents_model.rb +0 -2
- data/lib/anthropic/models/beta/beta_managed_agents_model_config.rb +5 -5
- data/lib/anthropic/models/beta/beta_managed_agents_multiagent.rb +1 -1
- data/lib/anthropic/models/beta/beta_managed_agents_multiagent_coordinator.rb +2 -2
- data/lib/anthropic/models/beta/beta_managed_agents_multiagent_params.rb +1 -1
- data/lib/anthropic/models/beta/beta_managed_agents_read_tool_config.rb +2 -2
- data/lib/anthropic/models/beta/beta_managed_agents_read_tool_config_params.rb +2 -2
- data/lib/anthropic/models/beta/beta_managed_agents_service_account_execution_identity.rb +21 -0
- data/lib/anthropic/models/beta/beta_managed_agents_service_account_execution_identity_params.rb +23 -0
- data/lib/anthropic/models/beta/beta_managed_agents_session_agent.rb +16 -6
- data/lib/anthropic/models/beta/beta_managed_agents_session_agent_update.rb +3 -3
- data/lib/anthropic/models/beta/beta_managed_agents_session_multiagent.rb +1 -1
- data/lib/anthropic/models/beta/beta_managed_agents_session_multiagent_coordinator.rb +8 -2
- data/lib/anthropic/models/beta/beta_managed_agents_session_resource_config.rb +3 -3
- data/lib/anthropic/models/beta/beta_managed_agents_session_thread_agent.rb +19 -6
- data/lib/anthropic/models/beta/beta_managed_agents_skill_params.rb +2 -2
- data/lib/anthropic/models/beta/beta_managed_agents_start_event_preview.rb +2 -2
- data/lib/anthropic/models/beta/beta_managed_agents_trigger_context.rb +2 -2
- data/lib/anthropic/models/beta/beta_managed_agents_user_tool_result_event.rb +4 -4
- data/lib/anthropic/models/beta/beta_managed_agents_web_fetch_tool_config.rb +2 -2
- data/lib/anthropic/models/beta/beta_managed_agents_web_fetch_tool_config_params.rb +2 -2
- data/lib/anthropic/models/beta/beta_managed_agents_web_search_tool_config.rb +2 -2
- data/lib/anthropic/models/beta/beta_managed_agents_web_search_tool_config_params.rb +2 -2
- data/lib/anthropic/models/beta/beta_managed_agents_write_tool_config.rb +2 -2
- data/lib/anthropic/models/beta/beta_managed_agents_write_tool_config_params.rb +2 -2
- data/lib/anthropic/models/beta/beta_message_delta_usage.rb +0 -1
- data/lib/anthropic/models/beta/beta_output_behavior.rb +2 -2
- data/lib/anthropic/models/beta/beta_thinking_config_adaptive.rb +6 -4
- data/lib/anthropic/models/beta/beta_thinking_config_enabled.rb +6 -4
- data/lib/anthropic/models/beta/beta_thinking_config_param.rb +8 -7
- data/lib/anthropic/models/beta/beta_usage.rb +0 -1
- data/lib/anthropic/models/beta/deployment_create_params.rb +3 -3
- data/lib/anthropic/models/beta/deployment_update_params.rb +3 -3
- data/lib/anthropic/models/beta/memory_stores/beta_managed_agents_actor.rb +3 -3
- data/lib/anthropic/models/beta/memory_stores/beta_managed_agents_error.rb +6 -3
- data/lib/anthropic/models/beta/memory_stores/beta_managed_agents_memory_list_item.rb +2 -2
- data/lib/anthropic/models/beta/message_count_tokens_params.rb +15 -10
- data/lib/anthropic/models/beta/message_create_params.rb +21 -12
- data/lib/anthropic/models/beta/messages/batch_create_params.rb +21 -12
- data/lib/anthropic/models/beta/organization/beta_analytics_cost_bucketed_result.rb +3 -3
- data/lib/anthropic/models/beta/organization/beta_analytics_cost_users_item.rb +3 -3
- data/lib/anthropic/models/beta/organization/beta_analytics_usage_bucketed_result.rb +3 -3
- data/lib/anthropic/models/beta/organization/beta_analytics_usage_users_item.rb +3 -3
- data/lib/anthropic/models/beta/organization/beta_deleted_telemetry_destination.rb +30 -0
- data/lib/anthropic/models/beta/organization/beta_spend_limit.rb +2 -2
- data/lib/anthropic/models/beta/organization/beta_telemetry_destination.rb +118 -0
- data/lib/anthropic/models/beta/organization/beta_telemetry_destination_content_mode.rb +29 -0
- data/lib/anthropic/models/beta/organization/beta_telemetry_destination_delivery_health.rb +69 -0
- data/lib/anthropic/models/beta/organization/beta_telemetry_destination_disabled_reason.rb +73 -0
- data/lib/anthropic/models/beta/organization/beta_telemetry_destination_disabled_reason_caller.rb +21 -0
- data/lib/anthropic/models/beta/organization/beta_telemetry_destination_disabled_reason_invalid_address.rb +29 -0
- data/lib/anthropic/models/beta/organization/beta_telemetry_destination_disabled_reason_redirect.rb +23 -0
- data/lib/anthropic/models/beta/organization/beta_telemetry_destination_disabled_reason_sustained_failure.rb +25 -0
- data/lib/anthropic/models/beta/organization/beta_telemetry_destination_state.rb +71 -0
- data/lib/anthropic/models/beta/organization/beta_telemetry_destination_state_disabled.rb +36 -0
- data/lib/anthropic/models/beta/organization/beta_telemetry_destination_state_disabled_params.rb +24 -0
- data/lib/anthropic/models/beta/organization/beta_telemetry_destination_state_enabled.rb +21 -0
- data/lib/anthropic/models/beta/organization/beta_telemetry_destination_state_enabled_params.rb +23 -0
- data/lib/anthropic/models/beta/organization/beta_telemetry_destination_state_params.rb +61 -0
- data/lib/anthropic/models/beta/organization/beta_telemetry_destination_test_failure.rb +37 -0
- data/lib/anthropic/models/beta/organization/beta_telemetry_destination_test_response.rb +35 -0
- data/lib/anthropic/models/beta/organization/beta_telemetry_destination_test_result.rb +61 -0
- data/lib/anthropic/models/beta/organization/beta_telemetry_destination_test_success.rb +21 -0
- data/lib/anthropic/models/beta/organization/beta_telemetry_destination_traces.rb +61 -0
- data/lib/anthropic/models/beta/organization/beta_telemetry_destination_traces_params.rb +71 -0
- data/lib/anthropic/models/beta/organization/beta_telemetry_destination_workspaces.rb +69 -0
- data/lib/anthropic/models/beta/organization/beta_telemetry_destination_workspaces_all.rb +23 -0
- data/lib/anthropic/models/beta/organization/beta_telemetry_destination_workspaces_all_params.rb +23 -0
- data/lib/anthropic/models/beta/organization/beta_telemetry_destination_workspaces_exclude.rb +22 -0
- data/lib/anthropic/models/beta/organization/beta_telemetry_destination_workspaces_exclude_params.rb +49 -0
- data/lib/anthropic/models/beta/organization/beta_telemetry_destination_workspaces_include.rb +21 -0
- data/lib/anthropic/models/beta/organization/beta_telemetry_destination_workspaces_include_params.rb +49 -0
- data/lib/anthropic/models/beta/organization/beta_telemetry_destination_workspaces_params.rb +70 -0
- data/lib/anthropic/models/beta/organization/invite_create_params.rb +4 -2
- data/lib/anthropic/models/beta/organization/spend_limit_list_params.rb +2 -5
- data/lib/anthropic/models/beta/organization/telemetry_destination_create_params.rb +93 -0
- data/lib/anthropic/models/beta/organization/telemetry_destination_delete_params.rb +34 -0
- data/lib/anthropic/models/beta/organization/telemetry_destination_list_params.rb +62 -0
- data/lib/anthropic/models/beta/organization/telemetry_destination_retrieve_params.rb +34 -0
- data/lib/anthropic/models/beta/organization/telemetry_destination_test_params.rb +34 -0
- data/lib/anthropic/models/beta/organization/telemetry_destination_update_params.rb +120 -0
- data/lib/anthropic/models/beta/organization/telemetry_destinations/beta_deleted_telemetry_destination_workspace.rb +40 -0
- data/lib/anthropic/models/beta/organization/telemetry_destinations/beta_telemetry_destination_workspace.rb +52 -0
- data/lib/anthropic/models/beta/organization/telemetry_destinations/workspace_add_params.rb +44 -0
- data/lib/anthropic/models/beta/organization/telemetry_destinations/workspace_list_params.rb +57 -0
- data/lib/anthropic/models/beta/organization/telemetry_destinations/workspace_remove_params.rb +44 -0
- data/lib/anthropic/models/beta/organization/user_update_params.rb +4 -2
- data/lib/anthropic/models/beta/session_create_params.rb +5 -5
- data/lib/anthropic/models/beta/sessions/beta_managed_agents_agent_custom_tool_use_event.rb +3 -1
- data/lib/anthropic/models/beta/sessions/beta_managed_agents_agent_mcp_tool_result_event.rb +4 -4
- data/lib/anthropic/models/beta/sessions/beta_managed_agents_agent_message_event.rb +2 -2
- data/lib/anthropic/models/beta/sessions/beta_managed_agents_agent_thread_message_received_event.rb +4 -4
- data/lib/anthropic/models/beta/sessions/beta_managed_agents_agent_thread_message_sent_event.rb +4 -4
- data/lib/anthropic/models/beta/sessions/beta_managed_agents_agent_tool_result_event.rb +4 -4
- data/lib/anthropic/models/beta/sessions/beta_managed_agents_billing_error.rb +3 -3
- data/lib/anthropic/models/beta/sessions/beta_managed_agents_credential_host_unreachable_error.rb +3 -3
- data/lib/anthropic/models/beta/sessions/beta_managed_agents_document_block.rb +4 -4
- data/lib/anthropic/models/beta/sessions/beta_managed_agents_event_params.rb +14 -8
- data/lib/anthropic/models/beta/sessions/beta_managed_agents_github_repository_resource.rb +2 -2
- data/lib/anthropic/models/beta/sessions/beta_managed_agents_image_block.rb +3 -3
- data/lib/anthropic/models/beta/sessions/beta_managed_agents_inline_agent.rb +14 -6
- data/lib/anthropic/models/beta/sessions/beta_managed_agents_mcp_authentication_failed_error.rb +3 -3
- data/lib/anthropic/models/beta/sessions/beta_managed_agents_mcp_connection_failed_error.rb +3 -3
- data/lib/anthropic/models/beta/sessions/beta_managed_agents_model_overloaded_error.rb +3 -3
- data/lib/anthropic/models/beta/sessions/beta_managed_agents_model_rate_limited_error.rb +3 -3
- data/lib/anthropic/models/beta/sessions/beta_managed_agents_model_request_failed_error.rb +3 -3
- data/lib/anthropic/models/beta/sessions/beta_managed_agents_repository_authentication_error.rb +3 -3
- data/lib/anthropic/models/beta/sessions/beta_managed_agents_repository_checkout_error.rb +3 -3
- data/lib/anthropic/models/beta/sessions/beta_managed_agents_repository_clone_error.rb +3 -3
- data/lib/anthropic/models/beta/sessions/beta_managed_agents_repository_forbidden_error.rb +3 -3
- data/lib/anthropic/models/beta/sessions/beta_managed_agents_repository_not_found_error.rb +3 -3
- data/lib/anthropic/models/beta/sessions/beta_managed_agents_send_session_events.rb +8 -8
- data/lib/anthropic/models/beta/sessions/beta_managed_agents_session_error_event.rb +14 -8
- data/lib/anthropic/models/beta/sessions/beta_managed_agents_session_event.rb +64 -37
- data/lib/anthropic/models/beta/sessions/beta_managed_agents_session_resource.rb +3 -3
- data/lib/anthropic/models/beta/sessions/beta_managed_agents_session_status_idle_event.rb +4 -4
- data/lib/anthropic/models/beta/sessions/beta_managed_agents_session_thread.rb +8 -2
- data/lib/anthropic/models/beta/sessions/beta_managed_agents_session_thread_status_idle_event.rb +4 -4
- data/lib/anthropic/models/beta/sessions/beta_managed_agents_stream_session_events.rb +66 -39
- data/lib/anthropic/models/beta/sessions/beta_managed_agents_stream_session_thread_events.rb +66 -39
- data/lib/anthropic/models/beta/sessions/beta_managed_agents_unknown_error.rb +3 -3
- data/lib/anthropic/models/beta/sessions/beta_managed_agents_user_custom_tool_result_event.rb +7 -7
- data/lib/anthropic/models/beta/sessions/beta_managed_agents_user_custom_tool_result_event_params.rb +7 -7
- data/lib/anthropic/models/beta/sessions/beta_managed_agents_user_define_outcome_event.rb +2 -2
- data/lib/anthropic/models/beta/sessions/beta_managed_agents_user_define_outcome_event_params.rb +2 -2
- data/lib/anthropic/models/beta/sessions/beta_managed_agents_user_message_event.rb +4 -4
- data/lib/anthropic/models/beta/sessions/beta_managed_agents_user_message_event_params.rb +4 -4
- data/lib/anthropic/models/beta/sessions/beta_managed_agents_user_tool_result_event_params.rb +4 -4
- data/lib/anthropic/models/beta/sessions/resource_retrieve_response.rb +3 -3
- data/lib/anthropic/models/beta/sessions/resource_update_response.rb +3 -3
- data/lib/anthropic/models/beta/vaults/beta_managed_agents_credential.rb +6 -3
- data/lib/anthropic/models/beta/vaults/beta_managed_agents_credential_networking_params.rb +7 -2
- data/lib/anthropic/models/beta/vaults/beta_managed_agents_environment_variable_auth_response.rb +7 -2
- data/lib/anthropic/models/beta/vaults/beta_managed_agents_mcp_oauth_refresh_params.rb +3 -3
- data/lib/anthropic/models/beta/vaults/beta_managed_agents_mcp_oauth_refresh_response.rb +12 -3
- data/lib/anthropic/models/beta/vaults/beta_managed_agents_mcp_oauth_refresh_update_params.rb +8 -2
- data/lib/anthropic/models/beta/vaults/credential_create_params.rb +6 -3
- data/lib/anthropic/models/beta/vaults/credential_update_params.rb +6 -3
- data/lib/anthropic/models/message_count_tokens_params.rb +15 -10
- data/lib/anthropic/models/message_create_params.rb +15 -10
- data/lib/anthropic/models/messages/batch_create_params.rb +15 -10
- data/lib/anthropic/models/model.rb +0 -2
- data/lib/anthropic/models/organization/invite_create_params.rb +4 -2
- data/lib/anthropic/models/organization/user_update_params.rb +4 -2
- data/lib/anthropic/models/thinking_config_adaptive.rb +6 -4
- data/lib/anthropic/models/thinking_config_enabled.rb +6 -4
- data/lib/anthropic/models/thinking_config_param.rb +8 -7
- data/lib/anthropic/request_options.rb +7 -0
- data/lib/anthropic/resources/beta/agents/versions.rb +4 -0
- data/lib/anthropic/resources/beta/agents.rb +22 -2
- data/lib/anthropic/resources/beta/deployment_runs.rb +16 -0
- data/lib/anthropic/resources/beta/deployments.rb +24 -0
- data/lib/anthropic/resources/beta/dreams.rb +15 -0
- data/lib/anthropic/resources/beta/environments/work.rb +42 -0
- data/lib/anthropic/resources/beta/environments.rb +18 -0
- data/lib/anthropic/resources/beta/files.rb +15 -0
- data/lib/anthropic/resources/beta/memory_stores/memories.rb +31 -0
- data/lib/anthropic/resources/beta/memory_stores/memory_versions.rb +28 -0
- data/lib/anthropic/resources/beta/memory_stores.rb +18 -0
- data/lib/anthropic/resources/beta/messages/batches.rb +19 -1
- data/lib/anthropic/resources/beta/messages.rb +12 -4
- data/lib/anthropic/resources/beta/models.rb +6 -0
- data/lib/anthropic/resources/beta/organization/analytics/apps/chat/projects.rb +3 -0
- data/lib/anthropic/resources/beta/organization/analytics/artifacts.rb +3 -0
- data/lib/anthropic/resources/beta/organization/analytics/connectors.rb +4 -0
- data/lib/anthropic/resources/beta/organization/analytics/cost_report.rb +20 -0
- data/lib/anthropic/resources/beta/organization/analytics/plugins.rb +4 -0
- data/lib/anthropic/resources/beta/organization/analytics/skills.rb +4 -0
- data/lib/anthropic/resources/beta/organization/analytics/summaries.rb +3 -0
- data/lib/anthropic/resources/beta/organization/analytics/usage_report.rb +20 -0
- data/lib/anthropic/resources/beta/organization/analytics/user_cost_report.rb +23 -0
- data/lib/anthropic/resources/beta/organization/analytics/user_usage_report.rb +23 -0
- data/lib/anthropic/resources/beta/organization/analytics/users.rb +4 -0
- data/lib/anthropic/resources/beta/organization/api_keys.rb +9 -0
- data/lib/anthropic/resources/beta/organization/compliance_settings.rb +4 -0
- data/lib/anthropic/resources/beta/organization/external_keys.rb +18 -0
- data/lib/anthropic/resources/beta/organization/federation/issuers.rb +15 -0
- data/lib/anthropic/resources/beta/organization/federation/rules/workspaces.rb +14 -0
- data/lib/anthropic/resources/beta/organization/federation/rules.rb +15 -0
- data/lib/anthropic/resources/beta/organization/invites.rb +12 -0
- data/lib/anthropic/resources/beta/organization/plugin_marketplaces.rb +14 -0
- data/lib/anthropic/resources/beta/organization/plugins/installation_settings.rb +16 -0
- data/lib/anthropic/resources/beta/organization/plugins/shares.rb +4 -0
- data/lib/anthropic/resources/beta/organization/plugins/versions.rb +22 -0
- data/lib/anthropic/resources/beta/organization/plugins.rb +27 -0
- data/lib/anthropic/resources/beta/organization/rate_limits.rb +3 -0
- data/lib/anthropic/resources/beta/organization/rbac_groups/members.rb +14 -0
- data/lib/anthropic/resources/beta/organization/rbac_groups.rb +15 -0
- data/lib/anthropic/resources/beta/organization/rbac_roles/permissions.rb +4 -0
- data/lib/anthropic/resources/beta/organization/rbac_roles.rb +6 -0
- data/lib/anthropic/resources/beta/organization/service_accounts/workspaces.rb +14 -0
- data/lib/anthropic/resources/beta/organization/service_accounts.rb +15 -0
- data/lib/anthropic/resources/beta/organization/spend_limits/effective.rb +5 -2
- data/lib/anthropic/resources/beta/organization/spend_limits/increase_requests.rb +12 -0
- data/lib/anthropic/resources/beta/organization/spend_limits.rb +17 -7
- data/lib/anthropic/resources/beta/organization/telemetry_destinations/workspaces.rb +173 -0
- data/lib/anthropic/resources/beta/organization/telemetry_destinations.rb +274 -0
- data/lib/anthropic/resources/beta/organization/users.rb +12 -0
- data/lib/anthropic/resources/beta/organization/workspaces/members.rb +26 -0
- data/lib/anthropic/resources/beta/organization/workspaces/rate_limits.rb +4 -0
- data/lib/anthropic/resources/beta/organization/workspaces/service_accounts.rb +26 -0
- data/lib/anthropic/resources/beta/organization/workspaces.rb +15 -0
- data/lib/anthropic/resources/beta/organization.rb +7 -0
- data/lib/anthropic/resources/beta/sessions/events.rb +21 -1
- data/lib/anthropic/resources/beta/sessions/resources.rb +26 -0
- data/lib/anthropic/resources/beta/sessions/threads/events.rb +15 -1
- data/lib/anthropic/resources/beta/sessions/threads.rb +16 -0
- data/lib/anthropic/resources/beta/sessions.rb +32 -0
- data/lib/anthropic/resources/beta/skills/versions.rb +17 -0
- data/lib/anthropic/resources/beta/skills.rb +12 -0
- data/lib/anthropic/resources/beta/tunnels/certificates.rb +20 -0
- data/lib/anthropic/resources/beta/tunnels.rb +18 -0
- data/lib/anthropic/resources/beta/user_profiles.rb +15 -0
- data/lib/anthropic/resources/beta/vaults/credentials.rb +38 -0
- data/lib/anthropic/resources/beta/vaults.rb +18 -0
- data/lib/anthropic/resources/completions.rb +5 -1
- data/lib/anthropic/resources/files.rb +15 -0
- data/lib/anthropic/resources/messages/batches.rb +19 -1
- data/lib/anthropic/resources/messages.rb +12 -4
- data/lib/anthropic/resources/models.rb +6 -0
- data/lib/anthropic/resources/organization/api_keys.rb +9 -0
- data/lib/anthropic/resources/organization/compliance_settings.rb +4 -0
- data/lib/anthropic/resources/organization/external_keys.rb +18 -0
- data/lib/anthropic/resources/organization/federation/issuers.rb +15 -0
- data/lib/anthropic/resources/organization/federation/rules/workspaces.rb +14 -0
- data/lib/anthropic/resources/organization/federation/rules.rb +15 -0
- data/lib/anthropic/resources/organization/invites.rb +12 -0
- data/lib/anthropic/resources/organization/rate_limits.rb +3 -0
- data/lib/anthropic/resources/organization/service_accounts/workspaces.rb +14 -0
- data/lib/anthropic/resources/organization/service_accounts.rb +15 -0
- data/lib/anthropic/resources/organization/users.rb +12 -0
- data/lib/anthropic/resources/organization/workspaces/members.rb +26 -0
- data/lib/anthropic/resources/organization/workspaces/rate_limits.rb +4 -0
- data/lib/anthropic/resources/organization/workspaces/service_accounts.rb +26 -0
- data/lib/anthropic/resources/organization/workspaces.rb +15 -0
- data/lib/anthropic/resources/organization.rb +2 -0
- data/lib/anthropic/resources/skills/versions.rb +14 -0
- data/lib/anthropic/resources/skills.rb +12 -0
- data/lib/anthropic/version.rb +1 -1
- data/lib/anthropic.rb +58 -0
- data/rbi/anthropic/client.rbi +28 -0
- data/rbi/anthropic/helpers/aws/client.rbi +6 -2
- data/rbi/anthropic/helpers/bedrock/client.rbi +6 -2
- data/rbi/anthropic/helpers/bedrock/mantle_client.rbi +6 -2
- data/rbi/anthropic/helpers/google_cloud/client.rbi +6 -2
- data/rbi/anthropic/helpers/streaming/message_stream.rbi +4 -1
- data/rbi/anthropic/helpers/vertex/client.rbi +6 -2
- data/rbi/anthropic/internal/tracing.rbi +847 -0
- data/rbi/anthropic/internal/transport/base_client.rbi +93 -5
- data/rbi/anthropic/internal/type/base_stream.rbi +2 -0
- data/rbi/anthropic/models/anthropic_beta.rbi +5 -0
- data/rbi/anthropic/models/beta/agent_create_params.rbi +34 -3
- data/rbi/anthropic/models/beta/agent_update_params.rbi +34 -3
- data/rbi/anthropic/models/beta/beta_fallback_param.rbi +3 -2
- data/rbi/anthropic/models/beta/beta_fallbacks_param.rbi +6 -2
- data/rbi/anthropic/models/beta/beta_managed_agents_agent.rbi +17 -0
- data/rbi/anthropic/models/beta/beta_managed_agents_agent_with_overrides_params.rbi +3 -3
- data/rbi/anthropic/models/beta/beta_managed_agents_aws_role_execution_identity.rbi +40 -0
- data/rbi/anthropic/models/beta/beta_managed_agents_aws_role_execution_identity_params.rbi +42 -0
- data/rbi/anthropic/models/beta/beta_managed_agents_execution_identity.rbi +85 -0
- data/rbi/anthropic/models/beta/beta_managed_agents_execution_identity_params.rbi +87 -0
- data/rbi/anthropic/models/beta/beta_managed_agents_model.rbi +0 -2
- data/rbi/anthropic/models/beta/beta_managed_agents_service_account_execution_identity.rbi +32 -0
- data/rbi/anthropic/models/beta/beta_managed_agents_service_account_execution_identity_params.rbi +33 -0
- data/rbi/anthropic/models/beta/beta_managed_agents_session_agent.rbi +19 -0
- data/rbi/anthropic/models/beta/beta_managed_agents_session_multiagent_coordinator.rbi +9 -0
- data/rbi/anthropic/models/beta/beta_managed_agents_session_thread_agent.rbi +19 -0
- data/rbi/anthropic/models/beta/beta_message_delta_usage.rbi +0 -2
- data/rbi/anthropic/models/beta/beta_thinking_config_adaptive.rbi +9 -6
- data/rbi/anthropic/models/beta/beta_thinking_config_enabled.rbi +9 -6
- data/rbi/anthropic/models/beta/beta_thinking_config_param.rbi +11 -9
- data/rbi/anthropic/models/beta/beta_usage.rbi +0 -2
- data/rbi/anthropic/models/beta/message_count_tokens_params.rbi +28 -18
- data/rbi/anthropic/models/beta/message_create_params.rbi +40 -22
- data/rbi/anthropic/models/beta/messages/batch_create_params.rbi +40 -22
- data/rbi/anthropic/models/beta/organization/beta_analytics_cost_bucketed_result.rbi +6 -6
- data/rbi/anthropic/models/beta/organization/beta_analytics_cost_users_item.rbi +6 -6
- data/rbi/anthropic/models/beta/organization/beta_analytics_usage_bucketed_result.rbi +6 -6
- data/rbi/anthropic/models/beta/organization/beta_analytics_usage_users_item.rbi +6 -6
- data/rbi/anthropic/models/beta/organization/beta_deleted_telemetry_destination.rbi +39 -0
- data/rbi/anthropic/models/beta/organization/beta_spend_limit.rbi +4 -4
- data/rbi/anthropic/models/beta/organization/beta_telemetry_destination.rbi +191 -0
- data/rbi/anthropic/models/beta/organization/beta_telemetry_destination_content_mode.rbi +53 -0
- data/rbi/anthropic/models/beta/organization/beta_telemetry_destination_delivery_health.rbi +106 -0
- data/rbi/anthropic/models/beta/organization/beta_telemetry_destination_disabled_reason.rbi +95 -0
- data/rbi/anthropic/models/beta/organization/beta_telemetry_destination_disabled_reason_caller.rbi +31 -0
- data/rbi/anthropic/models/beta/organization/beta_telemetry_destination_disabled_reason_invalid_address.rbi +39 -0
- data/rbi/anthropic/models/beta/organization/beta_telemetry_destination_disabled_reason_redirect.rbi +33 -0
- data/rbi/anthropic/models/beta/organization/beta_telemetry_destination_disabled_reason_sustained_failure.rbi +35 -0
- data/rbi/anthropic/models/beta/organization/beta_telemetry_destination_state.rbi +99 -0
- data/rbi/anthropic/models/beta/organization/beta_telemetry_destination_state_disabled.rbi +66 -0
- data/rbi/anthropic/models/beta/organization/beta_telemetry_destination_state_disabled_params.rbi +34 -0
- data/rbi/anthropic/models/beta/organization/beta_telemetry_destination_state_enabled.rbi +31 -0
- data/rbi/anthropic/models/beta/organization/beta_telemetry_destination_state_enabled_params.rbi +33 -0
- data/rbi/anthropic/models/beta/organization/beta_telemetry_destination_state_params.rbi +81 -0
- data/rbi/anthropic/models/beta/organization/beta_telemetry_destination_test_failure.rbi +47 -0
- data/rbi/anthropic/models/beta/organization/beta_telemetry_destination_test_response.rbi +62 -0
- data/rbi/anthropic/models/beta/organization/beta_telemetry_destination_test_result.rbi +88 -0
- data/rbi/anthropic/models/beta/organization/beta_telemetry_destination_test_success.rbi +31 -0
- data/rbi/anthropic/models/beta/organization/beta_telemetry_destination_traces.rbi +97 -0
- data/rbi/anthropic/models/beta/organization/beta_telemetry_destination_traces_params.rbi +120 -0
- data/rbi/anthropic/models/beta/organization/beta_telemetry_destination_workspaces.rbi +93 -0
- data/rbi/anthropic/models/beta/organization/beta_telemetry_destination_workspaces_all.rbi +33 -0
- data/rbi/anthropic/models/beta/organization/beta_telemetry_destination_workspaces_all_params.rbi +33 -0
- data/rbi/anthropic/models/beta/organization/beta_telemetry_destination_workspaces_exclude.rbi +32 -0
- data/rbi/anthropic/models/beta/organization/beta_telemetry_destination_workspaces_exclude_params.rbi +80 -0
- data/rbi/anthropic/models/beta/organization/beta_telemetry_destination_workspaces_include.rbi +31 -0
- data/rbi/anthropic/models/beta/organization/beta_telemetry_destination_workspaces_include_params.rbi +80 -0
- data/rbi/anthropic/models/beta/organization/beta_telemetry_destination_workspaces_params.rbi +107 -0
- data/rbi/anthropic/models/beta/organization/invite_create_params.rbi +6 -3
- data/rbi/anthropic/models/beta/organization/spend_limit_list_params.rbi +2 -8
- data/rbi/anthropic/models/beta/organization/telemetry_destination_create_params.rbi +186 -0
- data/rbi/anthropic/models/beta/organization/telemetry_destination_delete_params.rbi +73 -0
- data/rbi/anthropic/models/beta/organization/telemetry_destination_list_params.rbi +114 -0
- data/rbi/anthropic/models/beta/organization/telemetry_destination_retrieve_params.rbi +73 -0
- data/rbi/anthropic/models/beta/organization/telemetry_destination_test_params.rbi +73 -0
- data/rbi/anthropic/models/beta/organization/telemetry_destination_update_params.rbi +264 -0
- data/rbi/anthropic/models/beta/organization/telemetry_destinations/beta_deleted_telemetry_destination_workspace.rbi +61 -0
- data/rbi/anthropic/models/beta/organization/telemetry_destinations/beta_telemetry_destination_workspace.rbi +73 -0
- data/rbi/anthropic/models/beta/organization/telemetry_destinations/workspace_add_params.rbi +84 -0
- data/rbi/anthropic/models/beta/organization/telemetry_destinations/workspace_list_params.rbi +100 -0
- data/rbi/anthropic/models/beta/organization/telemetry_destinations/workspace_remove_params.rbi +84 -0
- data/rbi/anthropic/models/beta/organization/user_update_params.rbi +6 -3
- data/rbi/anthropic/models/beta/sessions/beta_managed_agents_agent_custom_tool_use_event.rbi +3 -1
- data/rbi/anthropic/models/beta/sessions/beta_managed_agents_event_params.rbi +2 -2
- data/rbi/anthropic/models/beta/sessions/beta_managed_agents_inline_agent.rbi +17 -0
- data/rbi/anthropic/models/beta/sessions/beta_managed_agents_send_session_events.rbi +2 -2
- data/rbi/anthropic/models/beta/sessions/beta_managed_agents_session_event.rbi +2 -2
- data/rbi/anthropic/models/beta/sessions/beta_managed_agents_session_thread.rbi +9 -0
- data/rbi/anthropic/models/beta/sessions/beta_managed_agents_stream_session_events.rbi +2 -2
- data/rbi/anthropic/models/beta/sessions/beta_managed_agents_stream_session_thread_events.rbi +2 -2
- data/rbi/anthropic/models/beta/sessions/beta_managed_agents_user_custom_tool_result_event.rbi +4 -4
- data/rbi/anthropic/models/beta/sessions/beta_managed_agents_user_custom_tool_result_event_params.rbi +4 -4
- data/rbi/anthropic/models/message_count_tokens_params.rbi +28 -18
- data/rbi/anthropic/models/message_create_params.rbi +28 -18
- data/rbi/anthropic/models/messages/batch_create_params.rbi +28 -18
- data/rbi/anthropic/models/model.rbi +0 -2
- data/rbi/anthropic/models/organization/invite_create_params.rbi +6 -3
- data/rbi/anthropic/models/organization/user_update_params.rbi +6 -3
- data/rbi/anthropic/models/thinking_config_adaptive.rbi +9 -6
- data/rbi/anthropic/models/thinking_config_enabled.rbi +9 -6
- data/rbi/anthropic/models/thinking_config_param.rbi +11 -9
- data/rbi/anthropic/request_options.rbi +5 -0
- data/rbi/anthropic/resources/beta/agents.rbi +22 -2
- data/rbi/anthropic/resources/beta/messages/batches.rbi +2 -1
- data/rbi/anthropic/resources/beta/messages.rbi +56 -32
- data/rbi/anthropic/resources/beta/organization/invites.rbi +2 -1
- data/rbi/anthropic/resources/beta/organization/spend_limits/effective.rbi +2 -2
- data/rbi/anthropic/resources/beta/organization/spend_limits.rbi +5 -10
- data/rbi/anthropic/resources/beta/organization/telemetry_destinations/workspaces.rbi +124 -0
- data/rbi/anthropic/resources/beta/organization/telemetry_destinations.rbi +300 -0
- data/rbi/anthropic/resources/beta/organization/users.rbi +2 -1
- data/rbi/anthropic/resources/beta/organization.rbi +7 -0
- data/rbi/anthropic/resources/beta/sessions/events.rbi +2 -1
- data/rbi/anthropic/resources/beta/sessions/threads/events.rbi +2 -1
- data/rbi/anthropic/resources/completions.rbi +6 -1
- data/rbi/anthropic/resources/messages/batches.rbi +2 -1
- data/rbi/anthropic/resources/messages.rbi +44 -28
- data/rbi/anthropic/resources/organization/invites.rbi +2 -1
- data/rbi/anthropic/resources/organization/users.rbi +2 -1
- data/sig/anthropic/client.rbs +1 -0
- data/sig/anthropic/helpers/bedrock/client.rbs +2 -1
- data/sig/anthropic/helpers/google_cloud/client.rbs +2 -1
- data/sig/anthropic/helpers/streaming/message_stream.rbs +2 -2
- data/sig/anthropic/helpers/vertex/client.rbs +2 -1
- data/sig/anthropic/internal/tracing.rbs +477 -0
- data/sig/anthropic/internal/transport/base_client.rbs +37 -2
- data/sig/anthropic/internal/type/base_stream.rbs +1 -1
- data/sig/anthropic/models/anthropic_beta.rbs +2 -0
- data/sig/anthropic/models/beta/agent_create_params.rbs +5 -0
- data/sig/anthropic/models/beta/agent_update_params.rbs +5 -0
- data/sig/anthropic/models/beta/beta_managed_agents_agent.rbs +5 -0
- data/sig/anthropic/models/beta/beta_managed_agents_aws_role_execution_identity.rbs +20 -0
- data/sig/anthropic/models/beta/beta_managed_agents_aws_role_execution_identity_params.rbs +20 -0
- data/sig/anthropic/models/beta/beta_managed_agents_execution_identity.rbs +42 -0
- data/sig/anthropic/models/beta/beta_managed_agents_execution_identity_params.rbs +42 -0
- data/sig/anthropic/models/beta/beta_managed_agents_model.rbs +0 -2
- data/sig/anthropic/models/beta/beta_managed_agents_service_account_execution_identity.rbs +18 -0
- data/sig/anthropic/models/beta/beta_managed_agents_service_account_execution_identity_params.rbs +18 -0
- data/sig/anthropic/models/beta/beta_managed_agents_session_agent.rbs +5 -0
- data/sig/anthropic/models/beta/beta_managed_agents_session_multiagent_coordinator.rbs +2 -0
- data/sig/anthropic/models/beta/beta_managed_agents_session_thread_agent.rbs +5 -0
- data/sig/anthropic/models/beta/organization/beta_deleted_telemetry_destination.rbs +23 -0
- data/sig/anthropic/models/beta/organization/beta_telemetry_destination.rbs +74 -0
- data/sig/anthropic/models/beta/organization/beta_telemetry_destination_content_mode.rbs +23 -0
- data/sig/anthropic/models/beta/organization/beta_telemetry_destination_delivery_health.rbs +30 -0
- data/sig/anthropic/models/beta/organization/beta_telemetry_destination_disabled_reason.rbs +51 -0
- data/sig/anthropic/models/beta/organization/beta_telemetry_destination_disabled_reason_caller.rbs +18 -0
- data/sig/anthropic/models/beta/organization/beta_telemetry_destination_disabled_reason_invalid_address.rbs +18 -0
- data/sig/anthropic/models/beta/organization/beta_telemetry_destination_disabled_reason_redirect.rbs +18 -0
- data/sig/anthropic/models/beta/organization/beta_telemetry_destination_disabled_reason_sustained_failure.rbs +18 -0
- data/sig/anthropic/models/beta/organization/beta_telemetry_destination_state.rbs +42 -0
- data/sig/anthropic/models/beta/organization/beta_telemetry_destination_state_disabled.rbs +29 -0
- data/sig/anthropic/models/beta/organization/beta_telemetry_destination_state_disabled_params.rbs +18 -0
- data/sig/anthropic/models/beta/organization/beta_telemetry_destination_state_enabled.rbs +17 -0
- data/sig/anthropic/models/beta/organization/beta_telemetry_destination_state_enabled_params.rbs +18 -0
- data/sig/anthropic/models/beta/organization/beta_telemetry_destination_state_params.rbs +40 -0
- data/sig/anthropic/models/beta/organization/beta_telemetry_destination_test_failure.rbs +20 -0
- data/sig/anthropic/models/beta/organization/beta_telemetry_destination_test_response.rbs +29 -0
- data/sig/anthropic/models/beta/organization/beta_telemetry_destination_test_result.rbs +42 -0
- data/sig/anthropic/models/beta/organization/beta_telemetry_destination_test_success.rbs +17 -0
- data/sig/anthropic/models/beta/organization/beta_telemetry_destination_traces.rbs +39 -0
- data/sig/anthropic/models/beta/organization/beta_telemetry_destination_traces_params.rbs +41 -0
- data/sig/anthropic/models/beta/organization/beta_telemetry_destination_workspaces.rbs +45 -0
- data/sig/anthropic/models/beta/organization/beta_telemetry_destination_workspaces_all.rbs +17 -0
- data/sig/anthropic/models/beta/organization/beta_telemetry_destination_workspaces_all_params.rbs +17 -0
- data/sig/anthropic/models/beta/organization/beta_telemetry_destination_workspaces_exclude.rbs +17 -0
- data/sig/anthropic/models/beta/organization/beta_telemetry_destination_workspaces_exclude_params.rbs +25 -0
- data/sig/anthropic/models/beta/organization/beta_telemetry_destination_workspaces_include.rbs +17 -0
- data/sig/anthropic/models/beta/organization/beta_telemetry_destination_workspaces_include_params.rbs +25 -0
- data/sig/anthropic/models/beta/organization/beta_telemetry_destination_workspaces_params.rbs +48 -0
- data/sig/anthropic/models/beta/organization/telemetry_destination_create_params.rbs +65 -0
- data/sig/anthropic/models/beta/organization/telemetry_destination_delete_params.rbs +39 -0
- data/sig/anthropic/models/beta/organization/telemetry_destination_list_params.rbs +55 -0
- data/sig/anthropic/models/beta/organization/telemetry_destination_retrieve_params.rbs +39 -0
- data/sig/anthropic/models/beta/organization/telemetry_destination_test_params.rbs +39 -0
- data/sig/anthropic/models/beta/organization/telemetry_destination_update_params.rbs +79 -0
- data/sig/anthropic/models/beta/organization/telemetry_destinations/beta_deleted_telemetry_destination_workspace.rbs +36 -0
- data/sig/anthropic/models/beta/organization/telemetry_destinations/beta_telemetry_destination_workspace.rbs +41 -0
- data/sig/anthropic/models/beta/organization/telemetry_destinations/workspace_add_params.rbs +46 -0
- data/sig/anthropic/models/beta/organization/telemetry_destinations/workspace_list_params.rbs +55 -0
- data/sig/anthropic/models/beta/organization/telemetry_destinations/workspace_remove_params.rbs +46 -0
- data/sig/anthropic/models/beta/sessions/beta_managed_agents_inline_agent.rbs +5 -0
- data/sig/anthropic/models/beta/sessions/beta_managed_agents_session_thread.rbs +3 -0
- data/sig/anthropic/models/model.rbs +0 -2
- data/sig/anthropic/request_options.rbs +3 -0
- data/sig/anthropic/resources/beta/agents.rbs +2 -0
- data/sig/anthropic/resources/beta/messages/batches.rbs +1 -1
- data/sig/anthropic/resources/beta/messages.rbs +1 -1
- data/sig/anthropic/resources/beta/organization/telemetry_destinations/workspaces.rbs +35 -0
- data/sig/anthropic/resources/beta/organization/telemetry_destinations.rbs +61 -0
- data/sig/anthropic/resources/beta/organization.rbs +2 -0
- data/sig/anthropic/resources/beta/sessions/events.rbs +1 -1
- data/sig/anthropic/resources/beta/sessions/threads/events.rbs +1 -1
- data/sig/anthropic/resources/completions.rbs +1 -1
- data/sig/anthropic/resources/messages/batches.rbs +1 -1
- data/sig/anthropic/resources/messages.rbs +1 -1
- metadata +178 -2
|
@@ -0,0 +1,1118 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Anthropic
|
|
4
|
+
module Internal
|
|
5
|
+
# @api private
|
|
6
|
+
#
|
|
7
|
+
# @generic Elem
|
|
8
|
+
#
|
|
9
|
+
# What a streaming method returns when its API call has a recording span. Reading
|
|
10
|
+
# or closing it reads or closes the SDK's own stream, and ends the span.
|
|
11
|
+
class TracedStream
|
|
12
|
+
include Anthropic::Internal::Type::BaseStream
|
|
13
|
+
|
|
14
|
+
# What a recorder that follows this stream has read of it.
|
|
15
|
+
# @return [Object, nil]
|
|
16
|
+
attr_reader :streamed_message
|
|
17
|
+
|
|
18
|
+
# @api private
|
|
19
|
+
#
|
|
20
|
+
# @param stream [Anthropic::Internal::Type::BaseStream] the SDK's own stream
|
|
21
|
+
#
|
|
22
|
+
# @param iterator [Enumerable<generic<Elem>>] reads `stream`, and ends the span
|
|
23
|
+
#
|
|
24
|
+
# @param streamed_message [Object, nil]
|
|
25
|
+
def initialize(stream, iterator, streamed_message)
|
|
26
|
+
@model = stream.instance_variable_get(:@model)
|
|
27
|
+
@status = stream.status
|
|
28
|
+
@headers = stream.headers
|
|
29
|
+
@iterator = iterator
|
|
30
|
+
@streamed_message = streamed_message
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# @api private
|
|
35
|
+
#
|
|
36
|
+
# One `CLIENT` span per API call: every retry of an SDK method's request, and
|
|
37
|
+
# reading the stream it returns. The SDK emits no span per HTTP attempt.
|
|
38
|
+
module Tracing
|
|
39
|
+
INSTRUMENTATION_SCOPE = "com.anthropic.sdk.ruby"
|
|
40
|
+
|
|
41
|
+
ERROR_TYPE = "error.type"
|
|
42
|
+
HTTP_REQUEST_METHOD = "http.request.method"
|
|
43
|
+
HTTP_REQUEST_RESEND_COUNT = "http.request.resend_count"
|
|
44
|
+
HTTP_RESPONSE_STATUS_CODE = "http.response.status_code"
|
|
45
|
+
HTTP_ROUTE = "http.route"
|
|
46
|
+
SERVER_ADDRESS = "server.address"
|
|
47
|
+
SERVER_PORT = "server.port"
|
|
48
|
+
URL_FULL = "url.full"
|
|
49
|
+
URL_PATH = "url.path"
|
|
50
|
+
URL_QUERY = "url.query"
|
|
51
|
+
URL_SCHEME = "url.scheme"
|
|
52
|
+
|
|
53
|
+
GEN_AI_PROVIDER_NAME = "gen_ai.provider.name"
|
|
54
|
+
ANTHROPIC_REQUEST_ID = "anthropic.request.id"
|
|
55
|
+
ANTHROPIC_ORGANIZATION_ID = "anthropic.organization.id"
|
|
56
|
+
ANTHROPIC_WORKSPACE_ID = "anthropic.workspace.id"
|
|
57
|
+
GEN_AI_OPERATION_NAME = "gen_ai.operation.name"
|
|
58
|
+
GEN_AI_REQUEST_MODEL = "gen_ai.request.model"
|
|
59
|
+
GEN_AI_REQUEST_MAX_TOKENS = "gen_ai.request.max_tokens"
|
|
60
|
+
GEN_AI_REQUEST_TEMPERATURE = "gen_ai.request.temperature"
|
|
61
|
+
GEN_AI_REQUEST_TOP_P = "gen_ai.request.top_p"
|
|
62
|
+
GEN_AI_REQUEST_TOP_K = "gen_ai.request.top_k"
|
|
63
|
+
GEN_AI_REQUEST_REASONING_LEVEL = "gen_ai.request.reasoning.level"
|
|
64
|
+
ANTHROPIC_REQUEST_SERVICE_TIER = "anthropic.request.service_tier"
|
|
65
|
+
ANTHROPIC_THINKING_TYPE = "anthropic.thinking.type"
|
|
66
|
+
ANTHROPIC_THINKING_BUDGET_TOKENS = "anthropic.thinking.budget_tokens"
|
|
67
|
+
ANTHROPIC_BETA = "anthropic.beta"
|
|
68
|
+
GEN_AI_REQUEST_STREAM = "gen_ai.request.stream"
|
|
69
|
+
GEN_AI_RESPONSE_ID = "gen_ai.response.id"
|
|
70
|
+
GEN_AI_RESPONSE_MODEL = "gen_ai.response.model"
|
|
71
|
+
GEN_AI_USAGE_CACHE_WRITE_INPUT_TOKENS = "gen_ai.usage.cache_write.input_tokens"
|
|
72
|
+
GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS = "gen_ai.usage.cache_read.input_tokens"
|
|
73
|
+
ANTHROPIC_USAGE_CACHE_CREATION_EPHEMERAL_5M_INPUT_TOKENS =
|
|
74
|
+
"anthropic.usage.cache_creation.ephemeral_5m_input_tokens"
|
|
75
|
+
ANTHROPIC_USAGE_CACHE_CREATION_EPHEMERAL_1H_INPUT_TOKENS =
|
|
76
|
+
"anthropic.usage.cache_creation.ephemeral_1h_input_tokens"
|
|
77
|
+
ANTHROPIC_RESPONSE_SERVICE_TIER = "anthropic.response.service_tier"
|
|
78
|
+
GEN_AI_USAGE_OUTPUT_TOKENS = "gen_ai.usage.output_tokens"
|
|
79
|
+
GEN_AI_USAGE_REASONING_OUTPUT_TOKENS = "gen_ai.usage.reasoning.output_tokens"
|
|
80
|
+
ANTHROPIC_MESSAGE_STOP_REASON = "anthropic.message.stop_reason"
|
|
81
|
+
ANTHROPIC_MESSAGE_COUNT_TOKENS_INPUT_TOKENS = "anthropic.message.count_tokens.input_tokens"
|
|
82
|
+
ANTHROPIC_SESSION_ENVIRONMENT_ID = "anthropic.session.environment.id"
|
|
83
|
+
GEN_AI_AGENT_NAME = "gen_ai.agent.name"
|
|
84
|
+
|
|
85
|
+
# @api private
|
|
86
|
+
#
|
|
87
|
+
# The span name of each SDK method. Code that names a span through these fails to
|
|
88
|
+
# load once no method has the name.
|
|
89
|
+
module SpanName
|
|
90
|
+
COMPLETIONS_CREATE = "anthropic.completions.create"
|
|
91
|
+
MESSAGES_CREATE = "anthropic.messages.create"
|
|
92
|
+
MESSAGES_COUNT_TOKENS = "anthropic.messages.count_tokens"
|
|
93
|
+
MESSAGES_BATCHES_CREATE = "anthropic.messages.batches.create"
|
|
94
|
+
MESSAGES_BATCHES_RETRIEVE = "anthropic.messages.batches.retrieve"
|
|
95
|
+
MESSAGES_BATCHES_LIST = "anthropic.messages.batches.list"
|
|
96
|
+
MESSAGES_BATCHES_DELETE = "anthropic.messages.batches.delete"
|
|
97
|
+
MESSAGES_BATCHES_CANCEL = "anthropic.messages.batches.cancel"
|
|
98
|
+
MESSAGES_BATCHES_RESULTS = "anthropic.messages.batches.results"
|
|
99
|
+
MODELS_RETRIEVE = "anthropic.models.retrieve"
|
|
100
|
+
MODELS_LIST = "anthropic.models.list"
|
|
101
|
+
FILES_LIST = "anthropic.files.list"
|
|
102
|
+
FILES_DELETE = "anthropic.files.delete"
|
|
103
|
+
FILES_DOWNLOAD = "anthropic.files.download"
|
|
104
|
+
FILES_RETRIEVE_METADATA = "anthropic.files.retrieve_metadata"
|
|
105
|
+
FILES_UPLOAD = "anthropic.files.upload"
|
|
106
|
+
SKILLS_CREATE = "anthropic.skills.create"
|
|
107
|
+
SKILLS_RETRIEVE = "anthropic.skills.retrieve"
|
|
108
|
+
SKILLS_LIST = "anthropic.skills.list"
|
|
109
|
+
SKILLS_DELETE = "anthropic.skills.delete"
|
|
110
|
+
SKILLS_VERSIONS_CREATE = "anthropic.skills.versions.create"
|
|
111
|
+
SKILLS_VERSIONS_RETRIEVE = "anthropic.skills.versions.retrieve"
|
|
112
|
+
SKILLS_VERSIONS_LIST = "anthropic.skills.versions.list"
|
|
113
|
+
SKILLS_VERSIONS_DELETE = "anthropic.skills.versions.delete"
|
|
114
|
+
ORGANIZATION_RETRIEVE = "anthropic.organization.retrieve"
|
|
115
|
+
ORGANIZATION_API_KEYS_RETRIEVE = "anthropic.organization.api_keys.retrieve"
|
|
116
|
+
ORGANIZATION_API_KEYS_UPDATE = "anthropic.organization.api_keys.update"
|
|
117
|
+
ORGANIZATION_API_KEYS_LIST = "anthropic.organization.api_keys.list"
|
|
118
|
+
ORGANIZATION_EXTERNAL_KEYS_CREATE = "anthropic.organization.external_keys.create"
|
|
119
|
+
ORGANIZATION_EXTERNAL_KEYS_RETRIEVE = "anthropic.organization.external_keys.retrieve"
|
|
120
|
+
ORGANIZATION_EXTERNAL_KEYS_UPDATE = "anthropic.organization.external_keys.update"
|
|
121
|
+
ORGANIZATION_EXTERNAL_KEYS_LIST = "anthropic.organization.external_keys.list"
|
|
122
|
+
ORGANIZATION_EXTERNAL_KEYS_DELETE = "anthropic.organization.external_keys.delete"
|
|
123
|
+
ORGANIZATION_EXTERNAL_KEYS_VALIDATE = "anthropic.organization.external_keys.validate"
|
|
124
|
+
ORGANIZATION_FEDERATION_ISSUERS_CREATE = "anthropic.organization.federation.issuers.create"
|
|
125
|
+
ORGANIZATION_FEDERATION_ISSUERS_RETRIEVE = "anthropic.organization.federation.issuers.retrieve"
|
|
126
|
+
ORGANIZATION_FEDERATION_ISSUERS_UPDATE = "anthropic.organization.federation.issuers.update"
|
|
127
|
+
ORGANIZATION_FEDERATION_ISSUERS_LIST = "anthropic.organization.federation.issuers.list"
|
|
128
|
+
ORGANIZATION_FEDERATION_ISSUERS_ARCHIVE = "anthropic.organization.federation.issuers.archive"
|
|
129
|
+
ORGANIZATION_FEDERATION_RULES_CREATE = "anthropic.organization.federation.rules.create"
|
|
130
|
+
ORGANIZATION_FEDERATION_RULES_RETRIEVE = "anthropic.organization.federation.rules.retrieve"
|
|
131
|
+
ORGANIZATION_FEDERATION_RULES_UPDATE = "anthropic.organization.federation.rules.update"
|
|
132
|
+
ORGANIZATION_FEDERATION_RULES_LIST = "anthropic.organization.federation.rules.list"
|
|
133
|
+
ORGANIZATION_FEDERATION_RULES_ARCHIVE = "anthropic.organization.federation.rules.archive"
|
|
134
|
+
ORGANIZATION_FEDERATION_RULES_WORKSPACES_LIST = "anthropic.organization.federation.rules.workspaces.list"
|
|
135
|
+
ORGANIZATION_FEDERATION_RULES_WORKSPACES_ADD = "anthropic.organization.federation.rules.workspaces.add"
|
|
136
|
+
ORGANIZATION_FEDERATION_RULES_WORKSPACES_REMOVE =
|
|
137
|
+
"anthropic.organization.federation.rules.workspaces.remove"
|
|
138
|
+
ORGANIZATION_INVITES_CREATE = "anthropic.organization.invites.create"
|
|
139
|
+
ORGANIZATION_INVITES_RETRIEVE = "anthropic.organization.invites.retrieve"
|
|
140
|
+
ORGANIZATION_INVITES_LIST = "anthropic.organization.invites.list"
|
|
141
|
+
ORGANIZATION_INVITES_DELETE = "anthropic.organization.invites.delete"
|
|
142
|
+
ORGANIZATION_SERVICE_ACCOUNTS_CREATE = "anthropic.organization.service_accounts.create"
|
|
143
|
+
ORGANIZATION_SERVICE_ACCOUNTS_RETRIEVE = "anthropic.organization.service_accounts.retrieve"
|
|
144
|
+
ORGANIZATION_SERVICE_ACCOUNTS_UPDATE = "anthropic.organization.service_accounts.update"
|
|
145
|
+
ORGANIZATION_SERVICE_ACCOUNTS_LIST = "anthropic.organization.service_accounts.list"
|
|
146
|
+
ORGANIZATION_SERVICE_ACCOUNTS_ARCHIVE = "anthropic.organization.service_accounts.archive"
|
|
147
|
+
ORGANIZATION_SERVICE_ACCOUNTS_WORKSPACES_LIST = "anthropic.organization.service_accounts.workspaces.list"
|
|
148
|
+
ORGANIZATION_SERVICE_ACCOUNTS_WORKSPACES_ADD = "anthropic.organization.service_accounts.workspaces.add"
|
|
149
|
+
ORGANIZATION_SERVICE_ACCOUNTS_WORKSPACES_REMOVE =
|
|
150
|
+
"anthropic.organization.service_accounts.workspaces.remove"
|
|
151
|
+
ORGANIZATION_USERS_RETRIEVE = "anthropic.organization.users.retrieve"
|
|
152
|
+
ORGANIZATION_USERS_UPDATE = "anthropic.organization.users.update"
|
|
153
|
+
ORGANIZATION_USERS_LIST = "anthropic.organization.users.list"
|
|
154
|
+
ORGANIZATION_USERS_REMOVE = "anthropic.organization.users.remove"
|
|
155
|
+
ORGANIZATION_WORKSPACES_CREATE = "anthropic.organization.workspaces.create"
|
|
156
|
+
ORGANIZATION_WORKSPACES_RETRIEVE = "anthropic.organization.workspaces.retrieve"
|
|
157
|
+
ORGANIZATION_WORKSPACES_UPDATE = "anthropic.organization.workspaces.update"
|
|
158
|
+
ORGANIZATION_WORKSPACES_LIST = "anthropic.organization.workspaces.list"
|
|
159
|
+
ORGANIZATION_WORKSPACES_ARCHIVE = "anthropic.organization.workspaces.archive"
|
|
160
|
+
ORGANIZATION_WORKSPACES_RATE_LIMITS_LIST = "anthropic.organization.workspaces.rate_limits.list"
|
|
161
|
+
ORGANIZATION_WORKSPACES_MEMBERS_RETRIEVE = "anthropic.organization.workspaces.members.retrieve"
|
|
162
|
+
ORGANIZATION_WORKSPACES_MEMBERS_UPDATE = "anthropic.organization.workspaces.members.update"
|
|
163
|
+
ORGANIZATION_WORKSPACES_MEMBERS_LIST = "anthropic.organization.workspaces.members.list"
|
|
164
|
+
ORGANIZATION_WORKSPACES_MEMBERS_ADD = "anthropic.organization.workspaces.members.add"
|
|
165
|
+
ORGANIZATION_WORKSPACES_MEMBERS_REMOVE = "anthropic.organization.workspaces.members.remove"
|
|
166
|
+
ORGANIZATION_WORKSPACES_SERVICE_ACCOUNTS_RETRIEVE =
|
|
167
|
+
"anthropic.organization.workspaces.service_accounts.retrieve"
|
|
168
|
+
ORGANIZATION_WORKSPACES_SERVICE_ACCOUNTS_UPDATE =
|
|
169
|
+
"anthropic.organization.workspaces.service_accounts.update"
|
|
170
|
+
ORGANIZATION_WORKSPACES_SERVICE_ACCOUNTS_LIST = "anthropic.organization.workspaces.service_accounts.list"
|
|
171
|
+
ORGANIZATION_WORKSPACES_SERVICE_ACCOUNTS_ADD = "anthropic.organization.workspaces.service_accounts.add"
|
|
172
|
+
ORGANIZATION_WORKSPACES_SERVICE_ACCOUNTS_REMOVE =
|
|
173
|
+
"anthropic.organization.workspaces.service_accounts.remove"
|
|
174
|
+
ORGANIZATION_RATE_LIMITS_LIST = "anthropic.organization.rate_limits.list"
|
|
175
|
+
ORGANIZATION_COMPLIANCE_SETTINGS_RETRIEVE = "anthropic.organization.compliance_settings.retrieve"
|
|
176
|
+
ORGANIZATION_COMPLIANCE_SETTINGS_UPDATE = "anthropic.organization.compliance_settings.update"
|
|
177
|
+
AGENTS_CREATE = "anthropic.agents.create"
|
|
178
|
+
AGENTS_RETRIEVE = "anthropic.agents.retrieve"
|
|
179
|
+
AGENTS_UPDATE = "anthropic.agents.update"
|
|
180
|
+
AGENTS_LIST = "anthropic.agents.list"
|
|
181
|
+
AGENTS_ARCHIVE = "anthropic.agents.archive"
|
|
182
|
+
AGENTS_VERSIONS_LIST = "anthropic.agents.versions.list"
|
|
183
|
+
ENVIRONMENTS_CREATE = "anthropic.environments.create"
|
|
184
|
+
ENVIRONMENTS_RETRIEVE = "anthropic.environments.retrieve"
|
|
185
|
+
ENVIRONMENTS_UPDATE = "anthropic.environments.update"
|
|
186
|
+
ENVIRONMENTS_LIST = "anthropic.environments.list"
|
|
187
|
+
ENVIRONMENTS_DELETE = "anthropic.environments.delete"
|
|
188
|
+
ENVIRONMENTS_ARCHIVE = "anthropic.environments.archive"
|
|
189
|
+
ENVIRONMENTS_WORK_RETRIEVE = "anthropic.environments.work.retrieve"
|
|
190
|
+
ENVIRONMENTS_WORK_UPDATE = "anthropic.environments.work.update"
|
|
191
|
+
ENVIRONMENTS_WORK_LIST = "anthropic.environments.work.list"
|
|
192
|
+
ENVIRONMENTS_WORK_ACK = "anthropic.environments.work.ack"
|
|
193
|
+
ENVIRONMENTS_WORK_HEARTBEAT = "anthropic.environments.work.heartbeat"
|
|
194
|
+
ENVIRONMENTS_WORK_POLL = "anthropic.environments.work.poll"
|
|
195
|
+
ENVIRONMENTS_WORK_STATS = "anthropic.environments.work.stats"
|
|
196
|
+
ENVIRONMENTS_WORK_STOP = "anthropic.environments.work.stop"
|
|
197
|
+
SESSIONS_CREATE = "anthropic.sessions.create"
|
|
198
|
+
SESSIONS_RETRIEVE = "anthropic.sessions.retrieve"
|
|
199
|
+
SESSIONS_UPDATE = "anthropic.sessions.update"
|
|
200
|
+
SESSIONS_LIST = "anthropic.sessions.list"
|
|
201
|
+
SESSIONS_DELETE = "anthropic.sessions.delete"
|
|
202
|
+
SESSIONS_ARCHIVE = "anthropic.sessions.archive"
|
|
203
|
+
SESSIONS_EVENTS_LIST = "anthropic.sessions.events.list"
|
|
204
|
+
SESSIONS_EVENTS_SEND = "anthropic.sessions.events.send"
|
|
205
|
+
SESSIONS_EVENTS_STREAM = "anthropic.sessions.events.stream"
|
|
206
|
+
SESSIONS_RESOURCES_RETRIEVE = "anthropic.sessions.resources.retrieve"
|
|
207
|
+
SESSIONS_RESOURCES_UPDATE = "anthropic.sessions.resources.update"
|
|
208
|
+
SESSIONS_RESOURCES_LIST = "anthropic.sessions.resources.list"
|
|
209
|
+
SESSIONS_RESOURCES_DELETE = "anthropic.sessions.resources.delete"
|
|
210
|
+
SESSIONS_RESOURCES_ADD = "anthropic.sessions.resources.add"
|
|
211
|
+
SESSIONS_THREADS_RETRIEVE = "anthropic.sessions.threads.retrieve"
|
|
212
|
+
SESSIONS_THREADS_LIST = "anthropic.sessions.threads.list"
|
|
213
|
+
SESSIONS_THREADS_ARCHIVE = "anthropic.sessions.threads.archive"
|
|
214
|
+
SESSIONS_THREADS_EVENTS_LIST = "anthropic.sessions.threads.events.list"
|
|
215
|
+
SESSIONS_THREADS_EVENTS_STREAM = "anthropic.sessions.threads.events.stream"
|
|
216
|
+
DEPLOYMENTS_CREATE = "anthropic.deployments.create"
|
|
217
|
+
DEPLOYMENTS_RETRIEVE = "anthropic.deployments.retrieve"
|
|
218
|
+
DEPLOYMENTS_UPDATE = "anthropic.deployments.update"
|
|
219
|
+
DEPLOYMENTS_LIST = "anthropic.deployments.list"
|
|
220
|
+
DEPLOYMENTS_ARCHIVE = "anthropic.deployments.archive"
|
|
221
|
+
DEPLOYMENTS_PAUSE = "anthropic.deployments.pause"
|
|
222
|
+
DEPLOYMENTS_RUN = "anthropic.deployments.run"
|
|
223
|
+
DEPLOYMENTS_UNPAUSE = "anthropic.deployments.unpause"
|
|
224
|
+
DEPLOYMENT_RUNS_RETRIEVE = "anthropic.deployment_runs.retrieve"
|
|
225
|
+
DEPLOYMENT_RUNS_LIST = "anthropic.deployment_runs.list"
|
|
226
|
+
VAULTS_CREATE = "anthropic.vaults.create"
|
|
227
|
+
VAULTS_RETRIEVE = "anthropic.vaults.retrieve"
|
|
228
|
+
VAULTS_UPDATE = "anthropic.vaults.update"
|
|
229
|
+
VAULTS_LIST = "anthropic.vaults.list"
|
|
230
|
+
VAULTS_DELETE = "anthropic.vaults.delete"
|
|
231
|
+
VAULTS_ARCHIVE = "anthropic.vaults.archive"
|
|
232
|
+
VAULTS_CREDENTIALS_CREATE = "anthropic.vaults.credentials.create"
|
|
233
|
+
VAULTS_CREDENTIALS_RETRIEVE = "anthropic.vaults.credentials.retrieve"
|
|
234
|
+
VAULTS_CREDENTIALS_UPDATE = "anthropic.vaults.credentials.update"
|
|
235
|
+
VAULTS_CREDENTIALS_LIST = "anthropic.vaults.credentials.list"
|
|
236
|
+
VAULTS_CREDENTIALS_DELETE = "anthropic.vaults.credentials.delete"
|
|
237
|
+
VAULTS_CREDENTIALS_ARCHIVE = "anthropic.vaults.credentials.archive"
|
|
238
|
+
VAULTS_CREDENTIALS_MCP_OAUTH_VALIDATE = "anthropic.vaults.credentials.mcp_oauth_validate"
|
|
239
|
+
MEMORY_STORES_CREATE = "anthropic.memory_stores.create"
|
|
240
|
+
MEMORY_STORES_RETRIEVE = "anthropic.memory_stores.retrieve"
|
|
241
|
+
MEMORY_STORES_UPDATE = "anthropic.memory_stores.update"
|
|
242
|
+
MEMORY_STORES_LIST = "anthropic.memory_stores.list"
|
|
243
|
+
MEMORY_STORES_DELETE = "anthropic.memory_stores.delete"
|
|
244
|
+
MEMORY_STORES_ARCHIVE = "anthropic.memory_stores.archive"
|
|
245
|
+
MEMORY_STORES_MEMORIES_CREATE = "anthropic.memory_stores.memories.create"
|
|
246
|
+
MEMORY_STORES_MEMORIES_RETRIEVE = "anthropic.memory_stores.memories.retrieve"
|
|
247
|
+
MEMORY_STORES_MEMORIES_UPDATE = "anthropic.memory_stores.memories.update"
|
|
248
|
+
MEMORY_STORES_MEMORIES_LIST = "anthropic.memory_stores.memories.list"
|
|
249
|
+
MEMORY_STORES_MEMORIES_DELETE = "anthropic.memory_stores.memories.delete"
|
|
250
|
+
MEMORY_STORES_MEMORY_VERSIONS_RETRIEVE = "anthropic.memory_stores.memory_versions.retrieve"
|
|
251
|
+
MEMORY_STORES_MEMORY_VERSIONS_LIST = "anthropic.memory_stores.memory_versions.list"
|
|
252
|
+
MEMORY_STORES_MEMORY_VERSIONS_REDACT = "anthropic.memory_stores.memory_versions.redact"
|
|
253
|
+
SKILLS_VERSIONS_DOWNLOAD = "anthropic.skills.versions.download"
|
|
254
|
+
USER_PROFILES_CREATE = "anthropic.user_profiles.create"
|
|
255
|
+
USER_PROFILES_RETRIEVE = "anthropic.user_profiles.retrieve"
|
|
256
|
+
USER_PROFILES_UPDATE = "anthropic.user_profiles.update"
|
|
257
|
+
USER_PROFILES_LIST = "anthropic.user_profiles.list"
|
|
258
|
+
USER_PROFILES_CREATE_ENROLLMENT_URL = "anthropic.user_profiles.create_enrollment_url"
|
|
259
|
+
DREAMS_CREATE = "anthropic.dreams.create"
|
|
260
|
+
DREAMS_RETRIEVE = "anthropic.dreams.retrieve"
|
|
261
|
+
DREAMS_LIST = "anthropic.dreams.list"
|
|
262
|
+
DREAMS_ARCHIVE = "anthropic.dreams.archive"
|
|
263
|
+
DREAMS_CANCEL = "anthropic.dreams.cancel"
|
|
264
|
+
TUNNELS_CREATE = "anthropic.tunnels.create"
|
|
265
|
+
TUNNELS_RETRIEVE = "anthropic.tunnels.retrieve"
|
|
266
|
+
TUNNELS_LIST = "anthropic.tunnels.list"
|
|
267
|
+
TUNNELS_ARCHIVE = "anthropic.tunnels.archive"
|
|
268
|
+
TUNNELS_REVEAL_TOKEN = "anthropic.tunnels.reveal_token"
|
|
269
|
+
TUNNELS_ROTATE_TOKEN = "anthropic.tunnels.rotate_token"
|
|
270
|
+
TUNNELS_CERTIFICATES_CREATE = "anthropic.tunnels.certificates.create"
|
|
271
|
+
TUNNELS_CERTIFICATES_RETRIEVE = "anthropic.tunnels.certificates.retrieve"
|
|
272
|
+
TUNNELS_CERTIFICATES_LIST = "anthropic.tunnels.certificates.list"
|
|
273
|
+
TUNNELS_CERTIFICATES_ARCHIVE = "anthropic.tunnels.certificates.archive"
|
|
274
|
+
ORGANIZATION_ANALYTICS_SUMMARIES_LIST = "anthropic.organization.analytics.summaries.list"
|
|
275
|
+
ORGANIZATION_ANALYTICS_USERS_LIST = "anthropic.organization.analytics.users.list"
|
|
276
|
+
ORGANIZATION_ANALYTICS_APPS_CHAT_PROJECTS_LIST =
|
|
277
|
+
"anthropic.organization.analytics.apps.chat.projects.list"
|
|
278
|
+
ORGANIZATION_ANALYTICS_CONNECTORS_LIST = "anthropic.organization.analytics.connectors.list"
|
|
279
|
+
ORGANIZATION_ANALYTICS_PLUGINS_LIST = "anthropic.organization.analytics.plugins.list"
|
|
280
|
+
ORGANIZATION_ANALYTICS_SKILLS_LIST = "anthropic.organization.analytics.skills.list"
|
|
281
|
+
ORGANIZATION_ANALYTICS_ARTIFACTS_LIST = "anthropic.organization.analytics.artifacts.list"
|
|
282
|
+
ORGANIZATION_ANALYTICS_USAGE_REPORT_LIST = "anthropic.organization.analytics.usage_report.list"
|
|
283
|
+
ORGANIZATION_ANALYTICS_USER_USAGE_REPORT_LIST = "anthropic.organization.analytics.user_usage_report.list"
|
|
284
|
+
ORGANIZATION_ANALYTICS_COST_REPORT_LIST = "anthropic.organization.analytics.cost_report.list"
|
|
285
|
+
ORGANIZATION_ANALYTICS_USER_COST_REPORT_LIST = "anthropic.organization.analytics.user_cost_report.list"
|
|
286
|
+
ORGANIZATION_SPEND_LIMITS_RETRIEVE = "anthropic.organization.spend_limits.retrieve"
|
|
287
|
+
ORGANIZATION_SPEND_LIMITS_LIST = "anthropic.organization.spend_limits.list"
|
|
288
|
+
ORGANIZATION_SPEND_LIMITS_DELETE = "anthropic.organization.spend_limits.delete"
|
|
289
|
+
ORGANIZATION_SPEND_LIMITS_SET = "anthropic.organization.spend_limits.set"
|
|
290
|
+
ORGANIZATION_SPEND_LIMITS_EFFECTIVE_LIST = "anthropic.organization.spend_limits.effective.list"
|
|
291
|
+
ORGANIZATION_SPEND_LIMITS_INCREASE_REQUESTS_RETRIEVE =
|
|
292
|
+
"anthropic.organization.spend_limits.increase_requests.retrieve"
|
|
293
|
+
ORGANIZATION_SPEND_LIMITS_INCREASE_REQUESTS_LIST =
|
|
294
|
+
"anthropic.organization.spend_limits.increase_requests.list"
|
|
295
|
+
ORGANIZATION_SPEND_LIMITS_INCREASE_REQUESTS_APPROVE =
|
|
296
|
+
"anthropic.organization.spend_limits.increase_requests.approve"
|
|
297
|
+
ORGANIZATION_SPEND_LIMITS_INCREASE_REQUESTS_DENY =
|
|
298
|
+
"anthropic.organization.spend_limits.increase_requests.deny"
|
|
299
|
+
ORGANIZATION_RBAC_GROUPS_CREATE = "anthropic.organization.rbac_groups.create"
|
|
300
|
+
ORGANIZATION_RBAC_GROUPS_RETRIEVE = "anthropic.organization.rbac_groups.retrieve"
|
|
301
|
+
ORGANIZATION_RBAC_GROUPS_UPDATE = "anthropic.organization.rbac_groups.update"
|
|
302
|
+
ORGANIZATION_RBAC_GROUPS_LIST = "anthropic.organization.rbac_groups.list"
|
|
303
|
+
ORGANIZATION_RBAC_GROUPS_DELETE = "anthropic.organization.rbac_groups.delete"
|
|
304
|
+
ORGANIZATION_RBAC_GROUPS_MEMBERS_LIST = "anthropic.organization.rbac_groups.members.list"
|
|
305
|
+
ORGANIZATION_RBAC_GROUPS_MEMBERS_ADD = "anthropic.organization.rbac_groups.members.add"
|
|
306
|
+
ORGANIZATION_RBAC_GROUPS_MEMBERS_REMOVE = "anthropic.organization.rbac_groups.members.remove"
|
|
307
|
+
ORGANIZATION_RBAC_ROLES_RETRIEVE = "anthropic.organization.rbac_roles.retrieve"
|
|
308
|
+
ORGANIZATION_RBAC_ROLES_LIST = "anthropic.organization.rbac_roles.list"
|
|
309
|
+
ORGANIZATION_RBAC_ROLES_PERMISSIONS_LIST = "anthropic.organization.rbac_roles.permissions.list"
|
|
310
|
+
ORGANIZATION_PLUGINS_CREATE = "anthropic.organization.plugins.create"
|
|
311
|
+
ORGANIZATION_PLUGINS_RETRIEVE = "anthropic.organization.plugins.retrieve"
|
|
312
|
+
ORGANIZATION_PLUGINS_UPDATE = "anthropic.organization.plugins.update"
|
|
313
|
+
ORGANIZATION_PLUGINS_LIST = "anthropic.organization.plugins.list"
|
|
314
|
+
ORGANIZATION_PLUGINS_DELETE = "anthropic.organization.plugins.delete"
|
|
315
|
+
ORGANIZATION_PLUGINS_VERSIONS_CREATE = "anthropic.organization.plugins.versions.create"
|
|
316
|
+
ORGANIZATION_PLUGINS_VERSIONS_RETRIEVE = "anthropic.organization.plugins.versions.retrieve"
|
|
317
|
+
ORGANIZATION_PLUGINS_VERSIONS_LIST = "anthropic.organization.plugins.versions.list"
|
|
318
|
+
ORGANIZATION_PLUGINS_VERSIONS_DOWNLOAD = "anthropic.organization.plugins.versions.download"
|
|
319
|
+
ORGANIZATION_PLUGINS_INSTALLATION_SETTINGS_LIST =
|
|
320
|
+
"anthropic.organization.plugins.installation_settings.list"
|
|
321
|
+
ORGANIZATION_PLUGINS_INSTALLATION_SETTINGS_REMOVE =
|
|
322
|
+
"anthropic.organization.plugins.installation_settings.remove"
|
|
323
|
+
ORGANIZATION_PLUGINS_INSTALLATION_SETTINGS_SET =
|
|
324
|
+
"anthropic.organization.plugins.installation_settings.set"
|
|
325
|
+
ORGANIZATION_PLUGINS_SHARES_LIST = "anthropic.organization.plugins.shares.list"
|
|
326
|
+
ORGANIZATION_PLUGIN_MARKETPLACES_RETRIEVE = "anthropic.organization.plugin_marketplaces.retrieve"
|
|
327
|
+
ORGANIZATION_PLUGIN_MARKETPLACES_UPDATE = "anthropic.organization.plugin_marketplaces.update"
|
|
328
|
+
ORGANIZATION_PLUGIN_MARKETPLACES_LIST = "anthropic.organization.plugin_marketplaces.list"
|
|
329
|
+
ORGANIZATION_PLUGIN_MARKETPLACES_VALIDATE_ARCHIVE =
|
|
330
|
+
"anthropic.organization.plugin_marketplaces.validate_archive"
|
|
331
|
+
ORGANIZATION_PLUGIN_MARKETPLACES_VALIDATE_REPOSITORY =
|
|
332
|
+
"anthropic.organization.plugin_marketplaces.validate_repository"
|
|
333
|
+
ORGANIZATION_TELEMETRY_DESTINATIONS_CREATE = "anthropic.organization.telemetry_destinations.create"
|
|
334
|
+
ORGANIZATION_TELEMETRY_DESTINATIONS_RETRIEVE = "anthropic.organization.telemetry_destinations.retrieve"
|
|
335
|
+
ORGANIZATION_TELEMETRY_DESTINATIONS_UPDATE = "anthropic.organization.telemetry_destinations.update"
|
|
336
|
+
ORGANIZATION_TELEMETRY_DESTINATIONS_LIST = "anthropic.organization.telemetry_destinations.list"
|
|
337
|
+
ORGANIZATION_TELEMETRY_DESTINATIONS_DELETE = "anthropic.organization.telemetry_destinations.delete"
|
|
338
|
+
ORGANIZATION_TELEMETRY_DESTINATIONS_TEST = "anthropic.organization.telemetry_destinations.test"
|
|
339
|
+
ORGANIZATION_TELEMETRY_DESTINATIONS_WORKSPACES_LIST =
|
|
340
|
+
"anthropic.organization.telemetry_destinations.workspaces.list"
|
|
341
|
+
ORGANIZATION_TELEMETRY_DESTINATIONS_WORKSPACES_ADD =
|
|
342
|
+
"anthropic.organization.telemetry_destinations.workspaces.add"
|
|
343
|
+
ORGANIZATION_TELEMETRY_DESTINATIONS_WORKSPACES_REMOVE =
|
|
344
|
+
"anthropic.organization.telemetry_destinations.workspaces.remove"
|
|
345
|
+
end
|
|
346
|
+
|
|
347
|
+
# @type [Hash{String=>String}]
|
|
348
|
+
CLIENT_ATTRIBUTES = {GEN_AI_PROVIDER_NAME => "anthropic"}.freeze
|
|
349
|
+
|
|
350
|
+
# @type [Hash{String=>String}]
|
|
351
|
+
#
|
|
352
|
+
# Each attribute with the response header it comes from.
|
|
353
|
+
RESPONSE_HEADER_ATTRIBUTES =
|
|
354
|
+
{
|
|
355
|
+
ANTHROPIC_REQUEST_ID => "request-id",
|
|
356
|
+
ANTHROPIC_ORGANIZATION_ID => "anthropic-organization-id",
|
|
357
|
+
ANTHROPIC_WORKSPACE_ID => "anthropic-workspace-id"
|
|
358
|
+
}.freeze
|
|
359
|
+
|
|
360
|
+
# @type [Array<Symbol>]
|
|
361
|
+
CLIENT_OPTION_KEYS = [:tracer_provider, :propagation, :traces].freeze
|
|
362
|
+
|
|
363
|
+
# @type [Array<Symbol>]
|
|
364
|
+
TRACES_KEYS = [:enabled, :content_mode, :max_content_bytes].freeze
|
|
365
|
+
|
|
366
|
+
# @type [Array<Symbol>]
|
|
367
|
+
CONTENT_MODES = [:metadata_only, :content].freeze
|
|
368
|
+
|
|
369
|
+
# The most bytes the `content` attributes of one span hold when
|
|
370
|
+
# `max_content_bytes` sets no other bound.
|
|
371
|
+
DEFAULT_MAX_CONTENT_BYTES = 750_000
|
|
372
|
+
|
|
373
|
+
# @type [Array<Symbol>]
|
|
374
|
+
REQUEST_OPTION_KEYS = [:conversation_id].freeze
|
|
375
|
+
|
|
376
|
+
# @type [Array<String>]
|
|
377
|
+
#
|
|
378
|
+
# Query parameters whose value is content on every endpoint that defines them.
|
|
379
|
+
CONTENT_QUERY_PARAMETERS = %w[email path_prefix expected_content_sha256].freeze
|
|
380
|
+
|
|
381
|
+
# @type [Hash{String=>Hash{Symbol=>Object}}]
|
|
382
|
+
#
|
|
383
|
+
# By span name. `:request` and `:response` map an attribute to `[path, type]` in
|
|
384
|
+
# that body, `:request_headers` to `[header, type]`.
|
|
385
|
+
SPAN_ATTRIBUTES =
|
|
386
|
+
{
|
|
387
|
+
SpanName::MESSAGES_CREATE => {
|
|
388
|
+
constants: {
|
|
389
|
+
GEN_AI_OPERATION_NAME => "chat"
|
|
390
|
+
},
|
|
391
|
+
request: {
|
|
392
|
+
GEN_AI_REQUEST_MODEL => [[:model], :string],
|
|
393
|
+
GEN_AI_REQUEST_MAX_TOKENS => [[:max_tokens], :integer],
|
|
394
|
+
GEN_AI_REQUEST_TEMPERATURE => [[:temperature], :number],
|
|
395
|
+
GEN_AI_REQUEST_TOP_P => [[:top_p], :number],
|
|
396
|
+
GEN_AI_REQUEST_TOP_K => [[:top_k], :integer],
|
|
397
|
+
GEN_AI_REQUEST_REASONING_LEVEL => [[:output_config, :effort], :string],
|
|
398
|
+
ANTHROPIC_REQUEST_SERVICE_TIER => [[:service_tier], :string],
|
|
399
|
+
ANTHROPIC_THINKING_TYPE => [[:thinking, :type], :string],
|
|
400
|
+
ANTHROPIC_THINKING_BUDGET_TOKENS => [[:thinking, :budget_tokens], :integer]
|
|
401
|
+
},
|
|
402
|
+
request_headers: {
|
|
403
|
+
ANTHROPIC_BETA => ["anthropic-beta", [:string]]
|
|
404
|
+
},
|
|
405
|
+
stream: GEN_AI_REQUEST_STREAM,
|
|
406
|
+
response: {
|
|
407
|
+
GEN_AI_RESPONSE_ID => [[:id], :string],
|
|
408
|
+
GEN_AI_RESPONSE_MODEL => [[:model], :string],
|
|
409
|
+
GEN_AI_USAGE_CACHE_WRITE_INPUT_TOKENS => [[:usage, :cache_creation_input_tokens], :integer],
|
|
410
|
+
GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS => [[:usage, :cache_read_input_tokens], :integer],
|
|
411
|
+
ANTHROPIC_USAGE_CACHE_CREATION_EPHEMERAL_5M_INPUT_TOKENS => [
|
|
412
|
+
[:usage, :cache_creation, :ephemeral_5m_input_tokens], :integer
|
|
413
|
+
],
|
|
414
|
+
ANTHROPIC_USAGE_CACHE_CREATION_EPHEMERAL_1H_INPUT_TOKENS => [
|
|
415
|
+
[:usage, :cache_creation, :ephemeral_1h_input_tokens], :integer
|
|
416
|
+
],
|
|
417
|
+
ANTHROPIC_RESPONSE_SERVICE_TIER => [[:usage, :service_tier], :string],
|
|
418
|
+
GEN_AI_USAGE_OUTPUT_TOKENS => [[:usage, :output_tokens], :integer],
|
|
419
|
+
GEN_AI_USAGE_REASONING_OUTPUT_TOKENS => [
|
|
420
|
+
[:usage, :output_tokens_details, :thinking_tokens],
|
|
421
|
+
:integer
|
|
422
|
+
],
|
|
423
|
+
ANTHROPIC_MESSAGE_STOP_REASON => [[:stop_reason], :string]
|
|
424
|
+
}
|
|
425
|
+
},
|
|
426
|
+
SpanName::MESSAGES_COUNT_TOKENS => {
|
|
427
|
+
request: {
|
|
428
|
+
GEN_AI_REQUEST_MODEL => [[:model], :string]
|
|
429
|
+
},
|
|
430
|
+
response: {
|
|
431
|
+
ANTHROPIC_MESSAGE_COUNT_TOKENS_INPUT_TOKENS => [[:input_tokens], :integer]
|
|
432
|
+
}
|
|
433
|
+
},
|
|
434
|
+
SpanName::SESSIONS_CREATE => {
|
|
435
|
+
request: {
|
|
436
|
+
ANTHROPIC_SESSION_ENVIRONMENT_ID => [[:environment_id], :string]
|
|
437
|
+
},
|
|
438
|
+
response: {
|
|
439
|
+
GEN_AI_AGENT_NAME => [[:agent, :name], :string],
|
|
440
|
+
GEN_AI_REQUEST_MODEL => [[:agent, :model, :id], :string]
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
}.freeze
|
|
444
|
+
|
|
445
|
+
# By span name; `nil` holds the recorders of every API call.
|
|
446
|
+
@recorders = {}.freeze
|
|
447
|
+
|
|
448
|
+
class << self
|
|
449
|
+
# The settings of a client's spans, frozen: its `open_telemetry` option with
|
|
450
|
+
# Symbol keys, where `:traces` is a Hash that has every one of {TRACES_KEYS}.
|
|
451
|
+
# `true` and `false` are `{traces: <it>}`, and a `:traces` of `true` or `false` is
|
|
452
|
+
# `{enabled: <it>}`. `nil`, for a client that is given no option, is what the
|
|
453
|
+
# environment says, and the environment is read here and nowhere else. Any other
|
|
454
|
+
# option is complete: what it leaves unset has the default, and no variable is
|
|
455
|
+
# read.
|
|
456
|
+
#
|
|
457
|
+
# @param option [Hash{Symbol=>Object}, Boolean, nil]
|
|
458
|
+
#
|
|
459
|
+
# @raise [ArgumentError]
|
|
460
|
+
# @return [Hash{Symbol=>Object}]
|
|
461
|
+
def client_option(option)
|
|
462
|
+
option = environment_option if option.nil?
|
|
463
|
+
option = {traces: option} if [true, false].include?(option)
|
|
464
|
+
option = option_hash(option, CLIENT_OPTION_KEYS, "`open_telemetry`", "true, false or a Hash")
|
|
465
|
+
propagation = option[:propagation]
|
|
466
|
+
unless [true, false, nil].include?(propagation)
|
|
467
|
+
raise ArgumentError.new("`open_telemetry` [:propagation] must be true or false, got #{plain(propagation)}")
|
|
468
|
+
end
|
|
469
|
+
traces = option[:traces].nil? ? {} : option[:traces]
|
|
470
|
+
traces = {enabled: traces} if [true, false].include?(traces)
|
|
471
|
+
traces = option_hash(traces, TRACES_KEYS, "`open_telemetry` [:traces]", "true, false or a Hash")
|
|
472
|
+
enabled, mode, bytes = traces.values_at(*TRACES_KEYS)
|
|
473
|
+
unless [true, false, nil].include?(enabled)
|
|
474
|
+
raise ArgumentError.new("`open_telemetry` [:traces][:enabled] must be true or false, got #{plain(enabled)}")
|
|
475
|
+
end
|
|
476
|
+
unless [nil, *CONTENT_MODES, *CONTENT_MODES.map(&:to_s)].include?(mode)
|
|
477
|
+
modes = CONTENT_MODES.map(&:inspect).join(" or ")
|
|
478
|
+
raise ArgumentError.new("`open_telemetry` [:traces][:content_mode] must be #{modes}, got #{plain(mode)}")
|
|
479
|
+
end
|
|
480
|
+
unless bytes.nil? || (bytes.is_a?(Integer) && bytes >= 1)
|
|
481
|
+
raise ArgumentError.new(
|
|
482
|
+
"`open_telemetry` [:traces][:max_content_bytes] must be an Integer of 1 or more, got #{plain(bytes)}"
|
|
483
|
+
)
|
|
484
|
+
end
|
|
485
|
+
{
|
|
486
|
+
tracer_provider: option[:tracer_provider],
|
|
487
|
+
propagation: propagation.nil? || propagation,
|
|
488
|
+
traces: {
|
|
489
|
+
enabled: enabled.nil? || enabled,
|
|
490
|
+
content_mode: mode&.to_sym || :metadata_only,
|
|
491
|
+
max_content_bytes: bytes || DEFAULT_MAX_CONTENT_BYTES
|
|
492
|
+
}.freeze
|
|
493
|
+
}.freeze
|
|
494
|
+
end
|
|
495
|
+
|
|
496
|
+
# The `open_telemetry` request option with Symbol keys.
|
|
497
|
+
#
|
|
498
|
+
# @param option [Hash{Symbol=>Object}, nil]
|
|
499
|
+
#
|
|
500
|
+
# @raise [ArgumentError]
|
|
501
|
+
# @return [Hash{Symbol=>Object}]
|
|
502
|
+
def request_option(option)
|
|
503
|
+
option_hash(option.nil? ? {} : option, REQUEST_OPTION_KEYS, "Request `open_telemetry`", "a Hash")
|
|
504
|
+
end
|
|
505
|
+
|
|
506
|
+
# The tracer for a client, or `nil` when its spans are disabled.
|
|
507
|
+
#
|
|
508
|
+
# @param option [Hash{Symbol=>Object}] from {client_option}
|
|
509
|
+
#
|
|
510
|
+
# @param scope [String]
|
|
511
|
+
#
|
|
512
|
+
# @return [OpenTelemetry::Trace::Tracer, nil]
|
|
513
|
+
def tracer(option, scope = INSTRUMENTATION_SCOPE)
|
|
514
|
+
return nil unless option[:traces][:enabled]
|
|
515
|
+
|
|
516
|
+
provider = option[:tracer_provider] || OpenTelemetry.tracer_provider
|
|
517
|
+
provider.tracer(scope, Anthropic::VERSION)
|
|
518
|
+
end
|
|
519
|
+
|
|
520
|
+
# Whether a client's spans have the `content` attributes.
|
|
521
|
+
#
|
|
522
|
+
# @param option [Hash{Symbol=>Object}] from {client_option}
|
|
523
|
+
#
|
|
524
|
+
# @return [Boolean]
|
|
525
|
+
def content?(option) = option[:traces][:content_mode] == :content
|
|
526
|
+
|
|
527
|
+
# The most bytes the `content` attributes of one of a client's spans hold.
|
|
528
|
+
#
|
|
529
|
+
# @param option [Hash{Symbol=>Object}] from {client_option}
|
|
530
|
+
#
|
|
531
|
+
# @return [Integer]
|
|
532
|
+
def max_content_bytes(option) = option[:traces][:max_content_bytes]
|
|
533
|
+
|
|
534
|
+
# Whether a client's requests carry the trace context of their span.
|
|
535
|
+
#
|
|
536
|
+
# @param option [Hash{Symbol=>Object}] from {client_option}
|
|
537
|
+
#
|
|
538
|
+
# @return [Boolean]
|
|
539
|
+
def propagation?(option) = option[:propagation]
|
|
540
|
+
|
|
541
|
+
# Returns `nil` when `req` has no `span_name`, or when the span neither records
|
|
542
|
+
# nor propagates a trace context: with `propagation` off, a span whose context is
|
|
543
|
+
# valid is kept, for the application's HTTP instrumentation to propagate. A span
|
|
544
|
+
# that cannot start is `nil` too, and the call goes on without one.
|
|
545
|
+
#
|
|
546
|
+
# @param tracer [OpenTelemetry::Trace::Tracer]
|
|
547
|
+
#
|
|
548
|
+
# @param req [Hash{Symbol=>Object}] the request, as the SDK method gave it to `BaseClient#request`
|
|
549
|
+
#
|
|
550
|
+
# @param propagation [Boolean] whether the client's requests carry the trace context
|
|
551
|
+
#
|
|
552
|
+
# @return [OpenTelemetry::Trace::Span, nil]
|
|
553
|
+
def start_api_call_span(tracer, req, propagation:)
|
|
554
|
+
name = req[:span_name]
|
|
555
|
+
return nil if name.nil?
|
|
556
|
+
|
|
557
|
+
recording(name) do
|
|
558
|
+
span = tracer.start_span(name, attributes: req[:span_attributes], kind: :client)
|
|
559
|
+
span if span.recording? || (propagation ? !inject(span).empty? : span.context.valid?)
|
|
560
|
+
end
|
|
561
|
+
end
|
|
562
|
+
|
|
563
|
+
# `span_name` is `nil` for every API call. The span starts with what
|
|
564
|
+
# `recorder.start_attributes(client, req)` returns, without its `nil` values, and
|
|
565
|
+
# `recorder.record(span, result)` runs right before the span ends, or before a
|
|
566
|
+
# streamed body takes the span with it. An error that either raises is logged, and
|
|
567
|
+
# does not fail the API call.
|
|
568
|
+
#
|
|
569
|
+
# @param span_name [String, nil] one of {SpanName}
|
|
570
|
+
#
|
|
571
|
+
# @param recorder [#start_attributes, #record]
|
|
572
|
+
#
|
|
573
|
+
# @return [void]
|
|
574
|
+
def register_recorder(span_name, recorder)
|
|
575
|
+
@recorders = {**@recorders, span_name => [*@recorders[span_name], recorder].freeze}.freeze
|
|
576
|
+
end
|
|
577
|
+
|
|
578
|
+
# A sampler reads only the attributes a span starts with, so everything known
|
|
579
|
+
# before the first attempt is here.
|
|
580
|
+
#
|
|
581
|
+
# @param client [Anthropic::Internal::Transport::BaseClient]
|
|
582
|
+
#
|
|
583
|
+
# @param req [Hash{Symbol=>Object}] the request, as the SDK method gave it to `BaseClient#request`
|
|
584
|
+
#
|
|
585
|
+
# @return [Hash{String=>Object}]
|
|
586
|
+
def api_call_span_attributes(client, req)
|
|
587
|
+
url = client.base_url
|
|
588
|
+
name = req[:span_name]
|
|
589
|
+
attributes = {
|
|
590
|
+
SERVER_ADDRESS => url.hostname,
|
|
591
|
+
SERVER_PORT => url.port || {"https" => 443, "http" => 80}[url.scheme],
|
|
592
|
+
HTTP_REQUEST_METHOD => req[:method].to_s.upcase,
|
|
593
|
+
HTTP_ROUTE => req[:span_route],
|
|
594
|
+
**client.open_telemetry_attributes,
|
|
595
|
+
**recording(name) { request_attributes(client, req) }.to_h,
|
|
596
|
+
**req[:span_attributes].to_h
|
|
597
|
+
}
|
|
598
|
+
recorders(name).each do |recorder|
|
|
599
|
+
attributes.update(recording(name) { recorder.start_attributes(client, req) }.to_h)
|
|
600
|
+
end
|
|
601
|
+
attributes.compact
|
|
602
|
+
end
|
|
603
|
+
|
|
604
|
+
# The first send sets the URL attributes ({url_attributes}). Every later one, a
|
|
605
|
+
# retry or a followed redirect, counts toward `http.request.resend_count`.
|
|
606
|
+
#
|
|
607
|
+
# @param span [OpenTelemetry::Trace::Span]
|
|
608
|
+
#
|
|
609
|
+
# @param client [Anthropic::Internal::Transport::BaseClient]
|
|
610
|
+
#
|
|
611
|
+
# @param request [Hash{Symbol=>Object}] the request, as `BaseClient#send_request` has it
|
|
612
|
+
#
|
|
613
|
+
# @param url [URI::Generic]
|
|
614
|
+
#
|
|
615
|
+
# @return [void]
|
|
616
|
+
def record_send(span, client, request, url)
|
|
617
|
+
sends = request[:sends] = request[:sends].to_i + 1
|
|
618
|
+
recording(nil) do
|
|
619
|
+
next unless span.recording?
|
|
620
|
+
|
|
621
|
+
if sends == 1
|
|
622
|
+
span.add_attributes(
|
|
623
|
+
url_attributes(client, url, request[:span_query].to_a, request[:span_content_query].to_a)
|
|
624
|
+
)
|
|
625
|
+
else
|
|
626
|
+
span.set_attribute(HTTP_REQUEST_RESEND_COUNT, sends - 1)
|
|
627
|
+
end
|
|
628
|
+
end
|
|
629
|
+
end
|
|
630
|
+
|
|
631
|
+
# A field that `response` lacks, or whose type is not the attribute's, sets
|
|
632
|
+
# nothing.
|
|
633
|
+
#
|
|
634
|
+
# @param span [OpenTelemetry::Trace::Span]
|
|
635
|
+
# @param span_name [String, nil]
|
|
636
|
+
# @param response [Anthropic::Internal::Type::BaseModel, Hash{Symbol=>Object}]
|
|
637
|
+
#
|
|
638
|
+
# @return [void]
|
|
639
|
+
def set_response_attributes(span, span_name, response)
|
|
640
|
+
SPAN_ATTRIBUTES.dig(span_name, :response).to_h.each do |attribute, (path, type)|
|
|
641
|
+
value = attribute_value(dig(response, path), type)
|
|
642
|
+
span.set_attribute(attribute, value) unless value.nil?
|
|
643
|
+
end
|
|
644
|
+
end
|
|
645
|
+
|
|
646
|
+
# The trace context of `span` as request headers, with lowercase names: none when
|
|
647
|
+
# the propagator fails.
|
|
648
|
+
#
|
|
649
|
+
# @param span [OpenTelemetry::Trace::Span]
|
|
650
|
+
#
|
|
651
|
+
# @return [Hash{String=>String}]
|
|
652
|
+
def inject(span)
|
|
653
|
+
carrier = {}
|
|
654
|
+
recording(nil) do
|
|
655
|
+
OpenTelemetry.propagation.inject(carrier, context: OpenTelemetry::Trace.context_with_span(span))
|
|
656
|
+
carrier.transform_keys { _1.to_s.downcase }
|
|
657
|
+
end || {}
|
|
658
|
+
end
|
|
659
|
+
|
|
660
|
+
# The lowercase names of the headers that carry a trace context. A propagator may
|
|
661
|
+
# write headers that it does not list, so those {inject} writes for `span` count
|
|
662
|
+
# too. A propagator that fails to list its headers counts as listing the standard
|
|
663
|
+
# ones.
|
|
664
|
+
#
|
|
665
|
+
# @param span [OpenTelemetry::Trace::Span, nil]
|
|
666
|
+
#
|
|
667
|
+
# @return [Array<String>]
|
|
668
|
+
def trace_header_names(span)
|
|
669
|
+
standard = %w[traceparent tracestate baggage]
|
|
670
|
+
names = recording(nil) do
|
|
671
|
+
propagation = OpenTelemetry.propagation
|
|
672
|
+
fields = propagation.respond_to?(:fields) ? propagation.fields : standard
|
|
673
|
+
fields.map { _1.to_s.downcase }
|
|
674
|
+
end || standard
|
|
675
|
+
span ? names | inject(span).keys : names
|
|
676
|
+
end
|
|
677
|
+
|
|
678
|
+
# The status is `ERROR` for `result[:error]`, `OK` for `result[:data]`, and unset
|
|
679
|
+
# when the call has neither because the application stopped it, such as with
|
|
680
|
+
# `Interrupt`.
|
|
681
|
+
#
|
|
682
|
+
# @param span [OpenTelemetry::Trace::Span]
|
|
683
|
+
#
|
|
684
|
+
# @param result [Hash{Symbol=>Object}] the result of the API call, as far as the call got
|
|
685
|
+
#
|
|
686
|
+
# @option result [Hash{Symbol=>Object}] :req the request, as the SDK method gave it to `BaseClient#request`
|
|
687
|
+
#
|
|
688
|
+
# @option result [Anthropic::Internal::Transport::BaseClient] :client the client that makes the call
|
|
689
|
+
#
|
|
690
|
+
# @option result [Float] :start_time when the call started, on the monotonic clock
|
|
691
|
+
#
|
|
692
|
+
# @option result [Integer, nil] :status the status of the final response, when an attempt received one
|
|
693
|
+
#
|
|
694
|
+
# @option result [Hash{String=>String}, nil] :headers the headers of the final response
|
|
695
|
+
#
|
|
696
|
+
# @option result [Object] :data the decoded body, or a stream that reads it, when the call returned
|
|
697
|
+
#
|
|
698
|
+
# @option result [StandardError, nil] :error what the call failed with
|
|
699
|
+
#
|
|
700
|
+
# @option result [Enumerable<Object>, nil] :iterator the enumerator of a stream in `:data`: a recorder that follows the stream
|
|
701
|
+
# replaces it with one that reads through it
|
|
702
|
+
#
|
|
703
|
+
# @option result [Object] :streamed_message what such a recorder keeps of the stream, for the SDK's stream helpers
|
|
704
|
+
#
|
|
705
|
+
# @return [void]
|
|
706
|
+
def end_api_call_span(span, result)
|
|
707
|
+
recording(result[:req][:span_name]) do
|
|
708
|
+
next unless span.recording?
|
|
709
|
+
|
|
710
|
+
set_response_status_code(span, result)
|
|
711
|
+
set_response_header_attributes(span, result)
|
|
712
|
+
set_created_id(span, result)
|
|
713
|
+
record_result(span, result)
|
|
714
|
+
if result[:error]
|
|
715
|
+
set_error_status(span, result[:error])
|
|
716
|
+
elsif result.key?(:data)
|
|
717
|
+
span.status = OpenTelemetry::Trace::Status.ok
|
|
718
|
+
end
|
|
719
|
+
span.finish
|
|
720
|
+
end
|
|
721
|
+
end
|
|
722
|
+
|
|
723
|
+
# Returns the stream that the application gets in place of `stream`: it ends
|
|
724
|
+
# `span` when the read ends ({iterate_and_end_span}). `result` is as for
|
|
725
|
+
# {end_api_call_span}.
|
|
726
|
+
#
|
|
727
|
+
# @param span [OpenTelemetry::Trace::Span]
|
|
728
|
+
# @param stream [Anthropic::Internal::Type::BaseStream]
|
|
729
|
+
# @param result [Hash{Symbol=>Object}]
|
|
730
|
+
#
|
|
731
|
+
# @return [Anthropic::Internal::Type::BaseStream]
|
|
732
|
+
def end_api_call_span_when_stream_ends(span, stream, result)
|
|
733
|
+
recording(result[:req][:span_name]) do
|
|
734
|
+
next stream unless span.recording?
|
|
735
|
+
|
|
736
|
+
set_response_status_code(span, result)
|
|
737
|
+
set_response_header_attributes(span, result)
|
|
738
|
+
# A recorder that follows the stream wraps `result[:iterator]` first, so its read ends before the span does.
|
|
739
|
+
result[:iterator] = stream.to_enum
|
|
740
|
+
record_result(span, result)
|
|
741
|
+
sse = stream.is_a?(Anthropic::Internal::Stream)
|
|
742
|
+
iterator = iterate_and_end_span(result[:iterator], span, sse)
|
|
743
|
+
Anthropic::Internal::TracedStream.new(stream, iterator, result[:streamed_message])
|
|
744
|
+
end || stream
|
|
745
|
+
end
|
|
746
|
+
|
|
747
|
+
# Anything but a `StandardError`, such as `Interrupt`, is the application stopping
|
|
748
|
+
# the operation, which leaves the status unset.
|
|
749
|
+
#
|
|
750
|
+
# @param span [OpenTelemetry::Trace::Span]
|
|
751
|
+
# @param error [Exception]
|
|
752
|
+
#
|
|
753
|
+
# @return [void]
|
|
754
|
+
def set_error_status(span, error)
|
|
755
|
+
return unless error.is_a?(StandardError)
|
|
756
|
+
|
|
757
|
+
span.status = OpenTelemetry::Trace::Status.error
|
|
758
|
+
span.set_attribute(ERROR_TYPE, error_type(error))
|
|
759
|
+
end
|
|
760
|
+
|
|
761
|
+
# @api private
|
|
762
|
+
#
|
|
763
|
+
# `option` with Symbol keys. Raises unless it is a Hash whose keys are all in
|
|
764
|
+
# `keys`.
|
|
765
|
+
#
|
|
766
|
+
# @param option [Object]
|
|
767
|
+
# @param keys [Array<Symbol>]
|
|
768
|
+
# @param name [String]
|
|
769
|
+
# @param expected [String]
|
|
770
|
+
#
|
|
771
|
+
# @raise [ArgumentError]
|
|
772
|
+
# @return [Hash{Symbol=>Object}]
|
|
773
|
+
private def option_hash(option, keys, name, expected)
|
|
774
|
+
raise ArgumentError.new("#{name} must be #{expected}, got #{plain(option)}") unless option.is_a?(Hash)
|
|
775
|
+
|
|
776
|
+
# `to_h` first: a subclass, such as one with indifferent access, can turn the keys back.
|
|
777
|
+
option = option.to_h.transform_keys { _1.is_a?(String) ? _1.to_sym : _1 }
|
|
778
|
+
unknown = option.keys.find { !keys.include?(_1) }
|
|
779
|
+
return option if unknown.nil?
|
|
780
|
+
|
|
781
|
+
raise ArgumentError.new("#{name} keys must be one of #{keys}, got #{plain(unknown)}")
|
|
782
|
+
end
|
|
783
|
+
|
|
784
|
+
# @api private
|
|
785
|
+
#
|
|
786
|
+
# The option can hold a tracer provider or content, so an error message shows a
|
|
787
|
+
# value only when it is a plain one, and its class otherwise.
|
|
788
|
+
#
|
|
789
|
+
# @param value [Object]
|
|
790
|
+
#
|
|
791
|
+
# @return [String]
|
|
792
|
+
private def plain(value)
|
|
793
|
+
case value
|
|
794
|
+
when String, Symbol, Numeric, true, false, nil then value.inspect
|
|
795
|
+
else "a #{value.class}"
|
|
796
|
+
end
|
|
797
|
+
end
|
|
798
|
+
|
|
799
|
+
# @api private
|
|
800
|
+
#
|
|
801
|
+
# The `open_telemetry` option that the environment variables stand for. Only
|
|
802
|
+
# `false`, in any case, turns the spans or the propagation off.
|
|
803
|
+
#
|
|
804
|
+
# @return [Hash{Symbol=>Object}]
|
|
805
|
+
private def environment_option
|
|
806
|
+
{
|
|
807
|
+
propagation: !ENV["ANTHROPIC_OPEN_TELEMETRY_PROPAGATION"]&.casecmp?("false"),
|
|
808
|
+
traces: {
|
|
809
|
+
enabled: !ENV["ANTHROPIC_OPEN_TELEMETRY"]&.casecmp?("false"),
|
|
810
|
+
content_mode: environment_content_mode,
|
|
811
|
+
max_content_bytes: environment_max_content_bytes
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
end
|
|
815
|
+
|
|
816
|
+
# @api private
|
|
817
|
+
#
|
|
818
|
+
# Anything but `content`, in any case, is `:metadata_only`.
|
|
819
|
+
#
|
|
820
|
+
# @return [Symbol]
|
|
821
|
+
private def environment_content_mode
|
|
822
|
+
content = ENV["ANTHROPIC_OPEN_TELEMETRY_TRACES_CONTENT_MODE"].to_s.casecmp?("content")
|
|
823
|
+
content ? :content : :metadata_only
|
|
824
|
+
end
|
|
825
|
+
|
|
826
|
+
# @api private
|
|
827
|
+
#
|
|
828
|
+
# `nil` unless the variable is a whole number of 1 or more, in decimal digits.
|
|
829
|
+
#
|
|
830
|
+
# @return [Integer, nil]
|
|
831
|
+
private def environment_max_content_bytes
|
|
832
|
+
value = ENV["ANTHROPIC_OPEN_TELEMETRY_TRACES_MAX_CONTENT_BYTES"].to_s.strip
|
|
833
|
+
bytes = value.to_i if value.match?(/\A\d+\z/)
|
|
834
|
+
bytes if bytes&.positive?
|
|
835
|
+
end
|
|
836
|
+
|
|
837
|
+
# @api private
|
|
838
|
+
#
|
|
839
|
+
# @param span [OpenTelemetry::Trace::Span]
|
|
840
|
+
# @param result [Hash{Symbol=>Object}]
|
|
841
|
+
#
|
|
842
|
+
# @return [void]
|
|
843
|
+
private def set_response_status_code(span, result)
|
|
844
|
+
error = result[:error]
|
|
845
|
+
status = result[:status] || (error.status if error.is_a?(Anthropic::Errors::APIError))
|
|
846
|
+
span.set_attribute(HTTP_RESPONSE_STATUS_CODE, status) if status
|
|
847
|
+
end
|
|
848
|
+
|
|
849
|
+
# @api private
|
|
850
|
+
#
|
|
851
|
+
# `span_created_id` names the attribute for the created object's `id`, or, as
|
|
852
|
+
# `{"<attribute>" => :user_id}`, for another of its fields.
|
|
853
|
+
#
|
|
854
|
+
# @param span [OpenTelemetry::Trace::Span]
|
|
855
|
+
# @param result [Hash{Symbol=>Object}]
|
|
856
|
+
#
|
|
857
|
+
# @return [void]
|
|
858
|
+
private def set_created_id(span, result)
|
|
859
|
+
attribute = result[:req][:span_created_id]
|
|
860
|
+
created = result[:data]
|
|
861
|
+
return if attribute.nil? || !created.is_a?(Anthropic::Internal::Type::BaseModel)
|
|
862
|
+
|
|
863
|
+
attribute, field = attribute.is_a?(Hash) ? attribute.first : [attribute, :id]
|
|
864
|
+
id = created[field]
|
|
865
|
+
span.set_attribute(attribute, id) if id.is_a?(String)
|
|
866
|
+
end
|
|
867
|
+
|
|
868
|
+
# @api private
|
|
869
|
+
#
|
|
870
|
+
# @param span [OpenTelemetry::Trace::Span]
|
|
871
|
+
# @param result [Hash{Symbol=>Object}]
|
|
872
|
+
#
|
|
873
|
+
# @return [void]
|
|
874
|
+
private def set_response_header_attributes(span, result)
|
|
875
|
+
error = result[:error]
|
|
876
|
+
headers = result[:headers] || (error.headers if error.is_a?(Anthropic::Errors::APIError)) || {}
|
|
877
|
+
RESPONSE_HEADER_ATTRIBUTES.each do |attribute, header|
|
|
878
|
+
value = headers[header]
|
|
879
|
+
span.set_attribute(attribute, value) unless value.nil? || value.empty?
|
|
880
|
+
end
|
|
881
|
+
end
|
|
882
|
+
|
|
883
|
+
# @api private
|
|
884
|
+
#
|
|
885
|
+
# @param span [OpenTelemetry::Trace::Span]
|
|
886
|
+
# @param result [Hash{Symbol=>Object}]
|
|
887
|
+
#
|
|
888
|
+
# @return [void]
|
|
889
|
+
private def record_result(span, result)
|
|
890
|
+
name = result[:req][:span_name]
|
|
891
|
+
data = result[:data]
|
|
892
|
+
recording(name) { set_response_attributes(span, name, data) } if data.is_a?(Anthropic::Internal::Type::BaseModel)
|
|
893
|
+
recorders(name).each { |recorder| recording(name) { recorder.record(span, result) } }
|
|
894
|
+
end
|
|
895
|
+
|
|
896
|
+
# @api private
|
|
897
|
+
#
|
|
898
|
+
# @param span_name [String, nil]
|
|
899
|
+
#
|
|
900
|
+
# @return [Array<#start_attributes, #record>]
|
|
901
|
+
private def recorders(span_name)
|
|
902
|
+
span_name.nil? ? [*@recorders[nil]] : [*@recorders[nil], *@recorders[span_name]]
|
|
903
|
+
end
|
|
904
|
+
|
|
905
|
+
# @api private
|
|
906
|
+
#
|
|
907
|
+
# A failure to trace must not fail the API call, so an error raised in the block,
|
|
908
|
+
# such as one from a span processor of the application, is logged, and the value
|
|
909
|
+
# is then `nil`.
|
|
910
|
+
#
|
|
911
|
+
# @param span_name [String, nil]
|
|
912
|
+
#
|
|
913
|
+
# @return [Object]
|
|
914
|
+
private def recording(span_name)
|
|
915
|
+
yield
|
|
916
|
+
rescue StandardError => e
|
|
917
|
+
OpenTelemetry.logger.debug("#{INSTRUMENTATION_SCOPE}: could not record on the span #{span_name}: #{e.class}")
|
|
918
|
+
nil
|
|
919
|
+
end
|
|
920
|
+
|
|
921
|
+
# @api private
|
|
922
|
+
#
|
|
923
|
+
# `url.query` and `url.full` keep only the pairs whose name the endpoint defines
|
|
924
|
+
# (`query_names`, or one of them followed by `[]`), so none that the application
|
|
925
|
+
# added. Both are left out when a kept pair is content
|
|
926
|
+
# ({CONTENT_QUERY_PARAMETERS}, `content_names`) and the client's spans have none.
|
|
927
|
+
#
|
|
928
|
+
# @param client [Anthropic::Internal::Transport::BaseClient]
|
|
929
|
+
# @param url [URI::Generic]
|
|
930
|
+
# @param query_names [Array<String>]
|
|
931
|
+
# @param content_names [Array<String>]
|
|
932
|
+
#
|
|
933
|
+
# @return [Hash{String=>String}]
|
|
934
|
+
private def url_attributes(client, url, query_names, content_names)
|
|
935
|
+
pairs = url.query.to_s.split("&").filter_map do |pair|
|
|
936
|
+
name = URI.decode_www_form_component(pair.partition("=").first)
|
|
937
|
+
defined = [name, name.delete_suffix("[]")].find { query_names.include?(_1) }
|
|
938
|
+
[defined, pair] unless defined.nil?
|
|
939
|
+
end
|
|
940
|
+
attributes = {URL_SCHEME => url.scheme, URL_PATH => url.path}
|
|
941
|
+
content = pairs.any? do |defined, _|
|
|
942
|
+
CONTENT_QUERY_PARAMETERS.include?(defined) || content_names.include?(defined)
|
|
943
|
+
end
|
|
944
|
+
return attributes if content && !client.open_telemetry_content?
|
|
945
|
+
|
|
946
|
+
query = pairs.map(&:last).join("&") unless pairs.empty?
|
|
947
|
+
server = client.base_url
|
|
948
|
+
authority = url.port == url.default_port ? server.host : "#{server.host}:#{server.port}"
|
|
949
|
+
attributes[URL_QUERY] = query unless query.nil?
|
|
950
|
+
attributes[URL_FULL] = "#{url.scheme}://#{authority}#{url.path}#{"?#{query}" if query}"
|
|
951
|
+
attributes
|
|
952
|
+
end
|
|
953
|
+
|
|
954
|
+
# @api private
|
|
955
|
+
#
|
|
956
|
+
# @param client [Anthropic::Internal::Transport::BaseClient]
|
|
957
|
+
# @param req [Hash{Symbol=>Object}]
|
|
958
|
+
#
|
|
959
|
+
# @return [Hash{String=>Object}]
|
|
960
|
+
private def request_attributes(client, req)
|
|
961
|
+
table = SPAN_ATTRIBUTES[req[:span_name]]
|
|
962
|
+
return {} if table.nil?
|
|
963
|
+
|
|
964
|
+
attributes = {**table[:constants].to_h}
|
|
965
|
+
table[:request].to_h.each do |attribute, (path, type)|
|
|
966
|
+
attributes[attribute] = attribute_value(dig(req[:body], path), type)
|
|
967
|
+
end
|
|
968
|
+
unless table[:request_headers].nil?
|
|
969
|
+
headers = Anthropic::Internal::Util.normalized_headers(
|
|
970
|
+
client.headers,
|
|
971
|
+
req[:headers].to_h,
|
|
972
|
+
req[:options].to_h[:extra_headers].to_h
|
|
973
|
+
)
|
|
974
|
+
table[:request_headers].each do |attribute, (header, type)|
|
|
975
|
+
attributes[attribute] = header_value(headers[header], type)
|
|
976
|
+
end
|
|
977
|
+
end
|
|
978
|
+
attributes[table[:stream]] = true if table.key?(:stream) && req[:stream]
|
|
979
|
+
attributes
|
|
980
|
+
end
|
|
981
|
+
|
|
982
|
+
# @api private
|
|
983
|
+
#
|
|
984
|
+
# @param data [Object]
|
|
985
|
+
# @param path [Array<Symbol>]
|
|
986
|
+
#
|
|
987
|
+
# @return [Object]
|
|
988
|
+
private def dig(data, path)
|
|
989
|
+
path.reduce(data) do |value, field|
|
|
990
|
+
case value
|
|
991
|
+
in Hash | Anthropic::Internal::Type::BaseModel
|
|
992
|
+
value[field]
|
|
993
|
+
else
|
|
994
|
+
return nil
|
|
995
|
+
end
|
|
996
|
+
end
|
|
997
|
+
end
|
|
998
|
+
|
|
999
|
+
# @api private
|
|
1000
|
+
#
|
|
1001
|
+
# `nil` for a value of another type than `type`, so that a response this SDK
|
|
1002
|
+
# version does not know sets no attribute rather than a wrong one.
|
|
1003
|
+
#
|
|
1004
|
+
# @param value [Object]
|
|
1005
|
+
# @param type [Symbol, Array<Symbol>]
|
|
1006
|
+
#
|
|
1007
|
+
# @return [Object]
|
|
1008
|
+
private def attribute_value(value, type)
|
|
1009
|
+
case [type, value]
|
|
1010
|
+
in [:string | :any, String | Symbol]
|
|
1011
|
+
value.to_s
|
|
1012
|
+
in [:integer | :any, Integer] | [:boolean | :any, true | false] | [:any, Float]
|
|
1013
|
+
value
|
|
1014
|
+
in [:number, Numeric]
|
|
1015
|
+
value.to_f
|
|
1016
|
+
in [[inner], Array]
|
|
1017
|
+
values = value.map { attribute_value(_1, inner) }
|
|
1018
|
+
values unless values.any?(&:nil?)
|
|
1019
|
+
else
|
|
1020
|
+
nil
|
|
1021
|
+
end
|
|
1022
|
+
end
|
|
1023
|
+
|
|
1024
|
+
# @api private
|
|
1025
|
+
#
|
|
1026
|
+
# @param value [String, nil]
|
|
1027
|
+
# @param type [Symbol, Array<Symbol>]
|
|
1028
|
+
#
|
|
1029
|
+
# @return [Object]
|
|
1030
|
+
private def header_value(value, type)
|
|
1031
|
+
values = value.to_s.split(",").map(&:strip).reject(&:empty?)
|
|
1032
|
+
return nil if values.empty?
|
|
1033
|
+
|
|
1034
|
+
type.is_a?(Array) ? values : value.to_s
|
|
1035
|
+
end
|
|
1036
|
+
|
|
1037
|
+
# @api private
|
|
1038
|
+
#
|
|
1039
|
+
# The first iteration ends `span` exactly once, however the read ends: `OK` when
|
|
1040
|
+
# exhausted, `ERROR` when it fails, unset when the application closes it early.
|
|
1041
|
+
# Server-sent events have no end that this code knows, so the server ending them
|
|
1042
|
+
# (`events`) sets no status: whoever knows their end event does. A later iteration
|
|
1043
|
+
# reads `source` as is, without touching the span.
|
|
1044
|
+
#
|
|
1045
|
+
# @param source [Enumerator<Object>]
|
|
1046
|
+
# @param span [OpenTelemetry::Trace::Span]
|
|
1047
|
+
# @param events [Boolean]
|
|
1048
|
+
#
|
|
1049
|
+
# @return [Enumerator<Object>]
|
|
1050
|
+
private def iterate_and_end_span(source, span, events)
|
|
1051
|
+
claimed = false
|
|
1052
|
+
ended = false
|
|
1053
|
+
finish = lambda do |exhausted: false, error: nil|
|
|
1054
|
+
next if ended
|
|
1055
|
+
|
|
1056
|
+
ended = true
|
|
1057
|
+
recording(nil) do
|
|
1058
|
+
if error
|
|
1059
|
+
set_error_status(span, error)
|
|
1060
|
+
elsif exhausted && !events
|
|
1061
|
+
span.status = OpenTelemetry::Trace::Status.ok
|
|
1062
|
+
end
|
|
1063
|
+
span.finish
|
|
1064
|
+
end
|
|
1065
|
+
end
|
|
1066
|
+
|
|
1067
|
+
traced = Enumerator.new do |y|
|
|
1068
|
+
next source.each(&y) if claimed
|
|
1069
|
+
|
|
1070
|
+
claimed = true
|
|
1071
|
+
# An error raised in the application's block is not a read failure.
|
|
1072
|
+
yielding = false
|
|
1073
|
+
begin
|
|
1074
|
+
source.each do |item|
|
|
1075
|
+
yielding = true
|
|
1076
|
+
y << item
|
|
1077
|
+
yielding = false
|
|
1078
|
+
end
|
|
1079
|
+
finish.call(exhausted: true)
|
|
1080
|
+
rescue StandardError => e
|
|
1081
|
+
finish.call(error: (e unless yielding))
|
|
1082
|
+
raise
|
|
1083
|
+
ensure
|
|
1084
|
+
finish.call
|
|
1085
|
+
end
|
|
1086
|
+
end
|
|
1087
|
+
# The SDK closes a stream by rewinding its enumerator. That does not resume a read
|
|
1088
|
+
# suspended in `Enumerator#next`, whose `ensure` would never run, so the span ends here.
|
|
1089
|
+
traced.define_singleton_method(:rewind) do
|
|
1090
|
+
source.rewind
|
|
1091
|
+
finish.call
|
|
1092
|
+
self
|
|
1093
|
+
end
|
|
1094
|
+
traced
|
|
1095
|
+
end
|
|
1096
|
+
|
|
1097
|
+
# @api private
|
|
1098
|
+
#
|
|
1099
|
+
# @param error [StandardError]
|
|
1100
|
+
#
|
|
1101
|
+
# @return [String]
|
|
1102
|
+
private def error_type(error)
|
|
1103
|
+
case error
|
|
1104
|
+
in Anthropic::Errors::APITimeoutError
|
|
1105
|
+
"client_timeout_error"
|
|
1106
|
+
in Anthropic::Errors::APIConnectionError
|
|
1107
|
+
"connection_error"
|
|
1108
|
+
in Anthropic::Errors::APIError if error.status
|
|
1109
|
+
type = Anthropic::Internal::Util.dig(error.body, [:error, :type])
|
|
1110
|
+
type.is_a?(String) ? type : error.status.to_s
|
|
1111
|
+
else
|
|
1112
|
+
"client_error"
|
|
1113
|
+
end
|
|
1114
|
+
end
|
|
1115
|
+
end
|
|
1116
|
+
end
|
|
1117
|
+
end
|
|
1118
|
+
end
|