sentry-otel-exporter-setup
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSentry OTel Exporter Setup
Sentry OTel Exporter 配置指南
Terminology: Always capitalize “Sentry Exporter” when referring to the exporter
component.
Configure the OpenTelemetry Collector to send traces and logs to Sentry using the Sentry
Exporter.
术语规范:提及该导出器组件时,请始终大写“Sentry Exporter”。
配置OpenTelemetry Collector,通过Sentry Exporter将追踪数据与日志发送至Sentry。
Setup Overview
配置概述
Copy this checklist to track your progress:
OTel Exporter Setup:
- [ ] Step 1: Check for existing configuration
- [ ] Step 2: Check collector version and install if needed
- [ ] Step 3: Configure project creation settings
- [ ] Step 4: Write collector config
- [ ] Step 5: Add environment variable placeholders
- [ ] Step 6: Run the collector
- [ ] Step 7: Verify setup
- [ ] Step 8: Enable trace connectedness with OTLPIntegration (Python/Ruby/Node.js)复制以下清单追踪配置进度:
OTel Exporter 配置:
- [ ] 步骤1:检查现有配置
- [ ] 步骤2:检查Collector版本并按需安装
- [ ] 步骤3:配置项目创建设置
- [ ] 步骤4:编写Collector配置文件
- [ ] 步骤5:添加环境变量占位符
- [ ] 步骤6:运行Collector
- [ ] 步骤7:验证配置
- [ ] 步骤8:通过OTLPIntegration启用追踪关联(Python/Ruby/Node.js)Step 1: Check for Existing Configuration
步骤1:检查现有配置
Search for existing OpenTelemetry Collector configs by looking for YAML files containing
. Also check for files named ,
, or .
receivers:otel-collector-config.*collector-config.*otelcol.*If an existing config is found: Ask the user which approach they want:
- Modify existing config: Add Sentry Exporter to the existing file (recommended to avoid duplicates)
- Create separate config: Keep existing config unchanged and create a new one for testing
Wait for the user’s answer and record their choice before proceeding to Step 2. The
rest of the workflow depends on this decision.
If no config exists: Note that you’ll create a new in Step
4, then proceed to Step 2.
collector-config.yaml通过查找包含的YAML文件,搜索现有的OpenTelemetry Collector配置。同时检查命名为、或的文件。
receivers:otel-collector-config.*collector-config.*otelcol.*若找到现有配置:询问用户选择以下哪种方式:
- 修改现有配置:在现有文件中添加Sentry Exporter(推荐,避免重复配置)
- 创建独立配置:保留现有配置不变,新建配置用于测试
等待用户答复并记录选择后,再进入步骤2。后续流程将基于此决策推进。
若未找到配置:记录将在步骤4中创建新的,然后进入步骤2。
collector-config.yamlStep 2: Check Collector Version
步骤2:检查Collector版本
The Sentry Exporter requires otelcol-contrib v0.145.0 or later.
Sentry Exporter要求otelcol-contrib v0.145.0或更高版本。
Check for existing collector
检查现有Collector
- Run to check if it’s on PATH, or check for
which otelcol-contribin the project./otelcol-contrib - If found, run the appropriate version command and parse the version number
- Record the collector path (e.g., if on PATH, or
otelcol-contribif local) for use in later steps./otelcol-contrib
| Existing Version | Action |
|---|---|
| ≥ 0.145.0 | Skip to Step 3 — existing collector is compatible |
| < 0.145.0 | Proceed with installation below |
| Not installed | Proceed with installation below |
- 运行检查是否已添加至PATH,或在项目中查找
which otelcol-contrib./otelcol-contrib - 若找到,运行对应版本命令并解析版本号
- 记录Collector路径(例如:若在PATH中则为,本地文件则为
otelcol-contrib),供后续步骤使用./otelcol-contrib
| 现有版本 | 操作 |
|---|---|
| ≥ 0.145.0 | 跳过至步骤3——现有Collector兼容 |
| < 0.145.0 | 继续执行下方安装步骤 |
| 未安装 | 继续执行下方安装步骤 |
Installation
安装方式
Ask the user how they want to run the collector:
- Binary: Download from GitHub releases. No Docker required.
- Docker: Run as a container. Requires Docker installed.
询问用户希望运行Collector的方式:
- 二进制文件:从GitHub Releases下载,无需Docker
- Docker容器:以容器形式运行,需已安装Docker
Binary Installation
二进制文件安装
Fetch the latest release version from GitHub:
bash
curl -s https://api.github.com/repos/open-telemetry/opentelemetry-collector-releases/releases/latest | grep '"tag_name"' | cut -d'"' -f4Important: The GitHub API returns versions with a prefix (e.g., ). The
download URL path requires the full tag with prefix, but the filename and Docker
tags use the numeric version without the prefix (e.g., ).
vv0.145.0v0.145.0Detect the user’s platform and download the binary:
- Run and
uname -sto detect OS and architectureuname -m - Map to release values:
- Darwin + arm64 →
darwin_arm64 - Darwin + x86_64 →
darwin_amd64 - Linux + x86_64 →
linux_amd64 - Linux + aarch64 →
linux_arm64
- Darwin + arm64 →
- Download and extract:
bash
curl -LO https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v<numeric_version>/otelcol-contrib_<numeric_version>_<os>_<arch>.tar.gz
tar -xzf otelcol-contrib_<numeric_version>_<os>_<arch>.tar.gz
chmod +x otelcol-contribExample: For version , the URL uses in the path but in
the filename.
v0.145.0v0.145.00.145.0Perform these steps for the user—do not just show them the commands.
- Ask the user if they want to delete the downloaded tarball to save disk space
(~50MB):
- Yes, delete it: Remove the tarball
- No, keep it: Leave the tarball in place
Wait for the user’s response. Only delete if they explicitly choose to:
bash
rm otelcol-contrib_<numeric_version>_<os>_<arch>.tar.gz从GitHub获取最新版本:
bash
curl -s https://api.github.com/repos/open-telemetry/opentelemetry-collector-releases/releases/latest | grep '"tag_name"' | cut -d'"' -f4注意:GitHub API返回的版本带有前缀(例如:)。下载URL路径需包含带前缀的完整标签,但文件名与Docker标签使用不带前缀的数字版本(例如:)。
vv0.145.0vv0.145.0检测用户平台并下载二进制文件:
- 运行和
uname -s检测操作系统与架构uname -m - 映射为对应版本值:
- Darwin + arm64 →
darwin_arm64 - Darwin + x86_64 →
darwin_amd64 - Linux + x86_64 →
linux_amd64 - Linux + aarch64 →
linux_arm64
- Darwin + arm64 →
- 下载并解压:
bash
curl -LO https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v<numeric_version>/otelcol-contrib_<numeric_version>_<os>_<arch>.tar.gz
tar -xzf otelcol-contrib_<numeric_version>_<os>_<arch>.tar.gz
chmod +x otelcol-contrib示例:对于版本,URL路径使用,但文件名使用。
v0.145.0v0.145.00.145.0为用户执行上述步骤——请勿仅展示命令。
- 询问用户是否删除下载的压缩包以节省磁盘空间(约50MB):
- 是,删除:移除压缩包
- 否,保留:保留压缩包
等待用户回复,仅在用户明确选择时执行删除:
bash
rm otelcol-contrib_<numeric_version>_<os>_<arch>.tar.gzDocker Installation
Docker安装
- Verify Docker is installed by running
docker --version - Fetch the latest release tag from GitHub (same as above)
- Pull the image using the numeric version (without prefix):
v
bash
docker pull otel/opentelemetry-collector-contrib:<numeric_version>Example: For GitHub tag , use
.
v0.145.0docker pull otel/opentelemetry-collector-contrib:0.145.0The command comes later in Step 6 after the config is created.
docker run- 运行验证Docker是否已安装
docker --version - 从GitHub获取最新版本标签(同上)
- 使用不带前缀的数字版本拉取镜像:
v
bash
docker pull otel/opentelemetry-collector-contrib:<numeric_version>示例:对于GitHub标签,使用。
v0.145.0docker pull otel/opentelemetry-collector-contrib:0.145.0docker runStep 3: Configure Sentry Project Creation
步骤3:配置Sentry项目创建
Ask the user whether to enable automatic Sentry project creation.
Do not recommend either option:
- Yes: Projects created from service.name. Requires at least one team in your Sentry org. All new projects are assigned to the first team found. Initial data may be dropped during creation.
- No: Projects must exist in Sentry before telemetry arrives.
Wait for the user’s answer before proceeding to Step 4.
If user chooses Yes: Warn them that the exporter will scan all projects and use the
first team it finds.
All auto-created projects will be assigned to that team.
If they don’t have any teams yet, they should create one in Sentry first.
询问用户是否启用Sentry项目自动创建功能。请勿推荐任一选项:
- 是:根据service.name创建项目,要求Sentry组织中至少有一个团队。所有新项目将分配给找到的第一个团队,创建过程中可能会丢弃初始数据。
- 否:遥测数据到达前,Sentry中必须已存在对应项目。
等待用户答复后,再进入步骤4。
若用户选择“是”:提醒用户导出器会扫描所有项目并使用找到的第一个团队,所有自动创建的项目将分配给该团队。若用户尚未创建任何团队,需先在Sentry中创建一个。
Step 4: Write Collector Config
步骤4:编写Collector配置文件
Use the decision from Step 1 - if the user chose to modify an existing config, edit
that file. If they chose to create a separate config, create a new file.
Record the config file path for use in Steps 5 and 6.
Fetch the latest configuration from the Sentry Exporter documentation:
- Example config (use as template):
https://raw.githubusercontent.com/open-telemetry/opentelemetry-collector-contrib/main/exporter/sentryexporter/docs/example-config.yaml - Full spec (all available options):
https://raw.githubusercontent.com/open-telemetry/opentelemetry-collector-contrib/main/exporter/sentryexporter/docs/spec.md
Use WebFetch to retrieve the example config as a starting template.
Reference the spec if the user needs advanced options not shown in the example.
依据步骤1的决策——若用户选择修改现有配置,则编辑该文件;若选择创建独立配置,则新建文件。记录配置文件路径,供步骤5和6使用。
从Sentry Exporter文档获取最新配置:
- 示例配置(用作模板):
https://raw.githubusercontent.com/open-telemetry/opentelemetry-collector-contrib/main/exporter/sentryexporter/docs/example-config.yaml - 完整规范(所有可用选项):
https://raw.githubusercontent.com/open-telemetry/opentelemetry-collector-contrib/main/exporter/sentryexporter/docs/spec.md
使用WebFetch获取示例配置作为起始模板。若用户需要示例中未展示的高级选项,请参考完整规范。
If editing an existing config (per Step 1 decision)
若编辑现有配置(基于步骤1的决策)
Add the exporter to the section and include it in the appropriate
pipelines (, ). Do not remove or modify other exporters unless the user
requests it.
sentryexporters:traceslogs在部分添加导出器,并将其加入对应流水线(、)。除非用户要求,否则请勿删除或修改其他导出器。
exporters:sentrytraceslogsIf creating a new config (per Step 1 decision)
若创建新配置(基于步骤1的决策)
Create based on the fetched example.
Ensure credentials use environment variable references (,
).
collector-config.yaml${env:SENTRY_ORG_SLUG}${env:SENTRY_AUTH_TOKEN}If user chose auto-create in Step 3, add to the sentry
exporter.
auto_create_projects: true基于获取的示例创建。确保凭证使用环境变量引用(、)。
collector-config.yaml${env:SENTRY_ORG_SLUG}${env:SENTRY_AUTH_TOKEN}若用户在步骤3中选择自动创建,请在sentry导出器中添加。
auto_create_projects: trueAdd Debug Exporter (Recommended)
添加Debug导出器(推荐)
For troubleshooting during setup, add a exporter with to
the pipelines. This logs all telemetry to console.
Remove it once setup is verified.
debugverbosity: detailed为便于配置过程中的故障排查,在流水线中添加导出器并设置,这会将所有遥测数据记录至控制台。验证完成后移除该导出器。
debugverbosity: detailedStep 5: Add Environment Variable Placeholders
步骤5:添加环境变量占位符
The Sentry Exporter requires two environment variables.
You will add placeholder values that the user fills in themselves—never actual
credentials.
Language constraint: NEVER say “add credentials”, “add environment variables”, or
“add the token” without explicitly stating these are placeholders. Always clarify
the user fills them in later.
DO NOT say:
- “Let me add the environment variables”
- “I’ll add the credentials to your .env”
- “Adding the Sentry auth token”
SAY INSTEAD:
- “I’ll add placeholder environment variables for you to fill in”
- “Adding placeholder values—you’ll replace these with your actual credentials”
- “I’ll set up the env var keys with placeholder values”
Search for existing files in the project using glob . Always ask the
user which file to use—do not infer from context or guess based on open files.
.env**/.envPresent the discovered options:
- [path to discovered .env file]: Add to existing file (list each discovered path)
- Create new at root: Create .env in project root
Wait for the user’s explicit selection. Do not proceed until they choose.
Record the env file path for use in Steps 5 (validation) and 6 (running).
Add these placeholder values to the chosen file:
bash
SENTRY_ORG_SLUG=your-org-slug
SENTRY_AUTH_TOKEN=your-token-hereAfter adding the placeholders, tell the user how to get their real values from Sentry:
- Sentry org slug: In Sentry, go to Settings → Organization Settings →
Organization Slug. This is also your subdomain (e.g., in
myorg)https://myorg.sentry.io - Sentry auth token: Create an Internal Integration in Sentry:
- In Sentry, go to Settings → Developer Settings → Custom Integrations
- Click Create New Integration → Choose Internal Integration
- Set permissions:
- Organization: Read — required
- Project: Read — required
- Project: Write — required only if using
auto_create_projects
- Save, then click Create New Token and copy it
Ensure the chosen file is in .
.env.gitignoreSentry Exporter需要两个环境变量。你将添加占位符值,由用户自行填写真实凭证——绝不能使用实际凭证。
语言约束:绝不能在未明确说明是占位符的情况下,使用“添加凭证”“添加环境变量”或“添加令牌”等表述。务必明确告知用户后续需自行替换这些占位符。
禁止使用:
- “我来添加环境变量”
- “我会将凭证添加到你的.env文件中”
- “添加Sentry认证令牌”
正确表述:
- “我将添加环境变量占位符,供你后续填写”
- “添加占位符值——你需将其替换为真实凭证”
- “我将设置环境变量键与占位符值”
使用通配符搜索项目中的现有.env文件。务必询问用户使用哪个文件——请勿根据上下文推断或基于打开的文件猜测。
**/.env展示找到的选项:
- [找到的.env文件路径]:添加至现有文件(列出所有找到的路径)
- 在根目录创建新文件:在项目根目录创建.env文件
等待用户明确选择,未选择前请勿继续。记录环境变量文件路径,供步骤5(验证)和6(运行)使用。
将以下占位符值添加至选定文件:
bash
SENTRY_ORG_SLUG=your-org-slug
SENTRY_AUTH_TOKEN=your-token-here添加占位符后,告知用户如何从Sentry获取真实值:
- Sentry组织标识(org slug):在Sentry中,前往设置 → 组织设置 → 组织标识。这也是你的子域名(例如:中的
https://myorg.sentry.io)myorg - Sentry认证令牌:在Sentry中创建内部集成:
- 前往设置 → 开发者设置 → 自定义集成
- 点击创建新集成 → 选择内部集成
- 设置权限:
- 组织:读取——必填
- 项目:读取——必填
- 项目:写入——仅在使用时必填
auto_create_projects
- 保存后,点击创建新令牌并复制
确保选定的.env文件已加入。
.gitignoreWait for user to set credentials
等待用户设置凭证
After explaining how to get the values, ask the user to confirm when they’ve updated the
file:
.env- Yes, credentials are set: Proceed to validate and run the collector
- Not yet: I’ll wait while you update the .env file
If user selects “Not yet”, wait and ask again.
Do not proceed to Step 6 until credentials are confirmed.
解释获取值的方法后,询问用户是否已更新.env文件:
- 是,已设置凭证:继续验证并运行Collector
- 尚未设置:我将等待你更新.env文件
若用户选择“尚未设置”,等待后再次询问。未确认凭证已设置前,请勿进入步骤6。
Validate config
验证配置
Once credentials are set, validate the configuration using the appropriate method based
on the installation choice from Step 2.
Use the config file path from Step 1 (either the existing config you modified or the
new ).
collector-config.yaml凭证设置完成后,根据步骤2选择的安装方式,使用对应方法验证配置。
使用步骤1中的配置文件路径(修改后的现有配置或新建的)。
collector-config.yamlBinary validation
二进制文件验证
Use the collector path recorded in Step 2 (either if on PATH, or
if local).
otelcol-contrib./otelcol-contribLoad environment variables first, then run validation:
bash
set -a && source "<env_file>" && set +a && "<collector_path>" validate --config "<config_file>"使用步骤2中记录的Collector路径(PATH中的或本地的)。
otelcol-contrib./otelcol-contrib先加载环境变量,再运行验证:
bash
set -a && source "<env_file>" && set +a && "<collector_path>" validate --config "<config_file>"Docker validation
Docker验证
Note: Docker volume mounts require absolute paths.
If or are relative paths, prefix them with . If
they’re already absolute paths, use them directly.
<config_file><env_file>$(pwd)/bash
docker run --rm \
-v "<config_file>":/etc/otelcol-contrib/config.yaml \
--env-file "<env_file>" \
otel/opentelemetry-collector-contrib:<numeric_version> \
validate --config /etc/otelcol-contrib/config.yamlUse the file path chosen in Step 5.
.envIf validation fails:
- Review the error message carefully
- Fix the issues in the config file
- Run validation again
- Repeat until validation passes
Once validation passes, ask the user if they’re ready to run the collector:
- Yes, run it now: Proceed to Step 6 and start the collector
- Not yet: Wait. The user may want to review the config or prepare their environment first.
Wait for the user’s confirmation before proceeding to Step 6.
注意:Docker卷挂载需要绝对路径。若或为相对路径,需添加前缀;若已为绝对路径,则直接使用。
<config_file><env_file>$(pwd)/bash
docker run --rm \
-v "<config_file>":/etc/otelcol-contrib/config.yaml \
--env-file "<env_file>" \
otel/opentelemetry-collector-contrib:<numeric_version> \
validate --config /etc/otelcol-contrib/config.yaml使用步骤5中选定的.env文件路径。
若验证失败:
- 仔细查看错误信息
- 修复配置文件中的问题
- 再次运行验证
- 重复直到验证通过
验证通过后,询问用户是否准备运行Collector:
- 是,现在运行:进入步骤6并启动Collector
- 尚未准备:等待,用户可能需要查看配置或准备环境
等待用户确认后,再进入步骤6。
Step 6: Run the Collector
步骤6:运行Collector
Only reach this step after the user confirms they’re ready to run the collector.
Give the user the run command but do not execute it automatically. The user will run
it themselves.
Provide the appropriate command based on the installation method chosen in Step 2.
Use the actual paths chosen earlier:
- Config file: From Step 1 (existing config or new )
collector-config.yaml - Env file: From Step 5 (the file the user selected)
.env - Collector path: From Step 2 (either if on PATH, or
otelcol-contribif local)./otelcol-contrib
仅在用户确认准备运行后,才进入此步骤。
为用户提供运行命令,但请勿自动执行,由用户自行运行。
根据步骤2选择的安装方式,提供对应命令。
使用之前选定的实际路径:
- 配置文件:来自步骤1(现有配置或新建的)
collector-config.yaml - 环境变量文件:来自步骤5(用户选定的.env文件)
- Collector路径:来自步骤2(PATH中的或本地的
otelcol-contrib)./otelcol-contrib
Binary
二进制文件
Load environment variables first, then run the collector:
bash
set -a && source "<env_file>" && set +a && "<collector_path>" --config "<config_file>"先加载环境变量,再运行Collector:
bash
set -a && source "<env_file>" && set +a && "<collector_path>" --config "<config_file>"Docker
Docker
Note: Docker volume mounts require absolute paths.
If or are relative paths, prefix them with . If
they’re already absolute paths, use them directly.
<config_file><env_file>$(pwd)/If re-running: Stop and remove any existing container first:
bash
docker stop otel-collector 2>/dev/null; docker rm otel-collector 2>/dev/nullbash
docker run -d \
--name otel-collector \
-p 4317:4317 \
-p 4318:4318 \
-p 13133:13133 \
-v "<config_file>":/etc/otelcol-contrib/config.yaml \
--env-file "<env_file>" \
otel/opentelemetry-collector-contrib:<numeric_version>Use the same numeric version (without prefix) that was pulled in Step 2.
vAfter providing the command, tell the user to run it when they’re ready, then proceed to
Step 7 for verification.
注意:Docker卷挂载需要绝对路径。若或为相对路径,需添加前缀;若已为绝对路径,则直接使用。
<config_file><env_file>$(pwd)/若重新运行:先停止并移除现有容器:
bash
docker stop otel-collector 2>/dev/null; docker rm otel-collector 2>/dev/nullbash
docker run -d \
--name otel-collector \
-p 4317:4317 \
-p 4318:4318 \
-p 13133:13133 \
-v "<config_file>":/etc/otelcol-contrib/config.yaml \
--env-file "<env_file>" \
otel/opentelemetry-collector-contrib:<numeric_version>使用步骤2中拉取的不带前缀的数字版本。
v提供命令后,告知用户准备好后运行,然后进入步骤7进行验证。
Step 7: Verify Setup
步骤7:验证配置
- Check collector logs for successful startup (no errors about invalid config or failed connections)
- Look for log messages indicating connection to Sentry
- Send test telemetry from an instrumented service and verify it appears in Sentry
Success criteria:
- Collector starts without errors
- Traces and/or logs appear in Sentry within 60 seconds of sending
If using Docker, check logs with .
docker logs otel-collector- 检查Collector日志,确认启动成功(无无效配置或连接失败的错误)
- 查找指示已连接至Sentry的日志信息
- 从已埋点的服务发送测试遥测数据,验证是否出现在Sentry中
成功标准:
- Collector启动无错误
- 发送后60秒内,追踪数据和/或日志出现在Sentry中
若使用Docker,可通过查看日志。
docker logs otel-collectorStep 8: Enable Trace Connectedness with OTLPIntegration
步骤8:通过OTLPIntegration启用追踪关联
If the user’s application uses a Sentry SDK (Python, Ruby, or Node.js), recommend
enabling the OTLPIntegration.
This ensures trace connectedness — linking OTel traces to Sentry errors, logs,
crons, and metrics — and sets up distributed tracing propagation automatically.
Without this step, traces sent through the collector appear in Sentry but are not
connected to other Sentry events (errors, logs) from the same service.
Ask the user: Does your application use the Sentry Python SDK, Sentry Ruby SDK, or
Sentry Node.js SDK?
- Python: Follow the Python setup below
- Ruby: Follow the Ruby setup below
- Node.js: Follow the Node.js setup below
- Neither / Other SDK: Skip this step. Trace connectedness via OTLPIntegration is currently available for Python, Ruby, and Node.js.
若用户的应用使用Sentry SDK(Python、Ruby或Node.js),建议启用OTLPIntegration。这确保追踪关联——将OTel追踪数据与Sentry的错误、日志、定时任务和指标关联,并自动设置分布式追踪传播。
若无此步骤,通过Collector发送的追踪数据会出现在Sentry中,但无法与同一服务的其他Sentry事件(错误、日志)关联。
询问用户:你的应用是否使用Sentry Python SDK、Sentry Ruby SDK或Sentry Node.js SDK?
- Python:按照下方Python配置步骤操作
- Ruby:按照下方Ruby配置步骤操作
- Node.js:按照下方Node.js配置步骤操作
- 都不使用/其他SDK:跳过此步骤。目前仅Python、Ruby和Node.js支持通过OTLPIntegration实现追踪关联。
Python OTLPIntegration
Python OTLPIntegration
- Install the extra:
bash
pip install "sentry-sdk[opentelemetry-otlp]"- Add the to the existing
OTLPIntegrationcall, settingsentry_sdk.init()to the collector’s OTLP traces endpoint:collector_url
python
from sentry_sdk.integrations.otlp import OTLPIntegration
sentry_sdk.init(
dsn="___PUBLIC_DSN___",
integrations=[
OTLPIntegration(collector_url="http://localhost:4318/v1/traces"),
],
)Use the collector’s actual OTLP HTTP endpoint.
The default is if running locally.
http://localhost:4318/v1/traces- 安装扩展包:
bash
pip install "sentry-sdk[opentelemetry-otlp]"- 在现有调用中添加
sentry_sdk.init(),将OTLPIntegration设置为Collector的OTLP追踪端点:collector_url
python
from sentry_sdk.integrations.otlp import OTLPIntegration
sentry_sdk.init(
dsn="___PUBLIC_DSN___",
integrations=[
OTLPIntegration(collector_url="http://localhost:4318/v1/traces"),
],
)使用Collector的实际OTLP HTTP端点。若在本地运行,默认值为。
http://localhost:4318/v1/tracesRuby OTLPIntegration
Ruby OTLPIntegration
- Add gems to the Gemfile:
ruby
gem "sentry-opentelemetry"
gem "opentelemetry-sdk"
gem "opentelemetry-exporter-otlp"
gem "opentelemetry-instrumentation-all"-
Run
bundle install -
Configure OpenTelemetry instrumentation:
ruby
OpenTelemetry::SDK.configure do |c|
c.use_all
end- Enable OTLP in the existing block, setting
Sentry.initto the collector’s OTLP traces endpoint:collector_url
ruby
Sentry.init do |config|
config.dsn = "___PUBLIC_DSN___"
config.otlp.enabled = true
config.otlp.collector_url = "http://localhost:4318/v1/traces"
endUse the collector’s actual OTLP HTTP endpoint.
The default is if running locally.
http://localhost:4318/v1/traces- 在Gemfile中添加依赖:
ruby
gem "sentry-opentelemetry"
gem "opentelemetry-sdk"
gem "opentelemetry-exporter-otlp"
gem "opentelemetry-instrumentation-all"-
运行
bundle install -
配置OpenTelemetry埋点:
ruby
OpenTelemetry::SDK.configure do |c|
c.use_all
end- 在现有块中启用OTLP,将
Sentry.init设置为Collector的OTLP追踪端点:collector_url
ruby
Sentry.init do |config|
config.dsn = "___PUBLIC_DSN___"
config.otlp.enabled = true
config.otlp.collector_url = "http://localhost:4318/v1/traces"
end使用Collector的实际OTLP HTTP端点。若在本地运行,默认值为。
http://localhost:4318/v1/tracesNode.js OTLPIntegration
Node.js OTLPIntegration
- Install the lightweight Sentry SDK and OpenTelemetry dependencies:
bash
npm install @sentry/node-core @opentelemetry/api @opentelemetry/sdk-trace-node @opentelemetry/sdk-trace-base- Create an instrument file () that sets up OTel and Sentry together:
instrument.mjs
javascript
import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
import * as Sentry from '@sentry/node-core/light';
import { otlpIntegration } from '@sentry/node-core/light/otlp';
const provider = new NodeTracerProvider();
provider.register();
Sentry.init({
dsn: '___PUBLIC_DSN___',
integrations: [
otlpIntegration({
collectorUrl: 'http://localhost:4318/v1/traces',
}),
],
});- Start your app with the flag:
--import
bash
node --import ./instrument.mjs app.mjsUse the collector’s actual OTLP HTTP endpoint.
The default is if running locally.
http://localhost:4318/v1/tracesDo not setwhen usingtracesSampleRate— OTel controls sampling. Setting it would conflict with the OTLP path.otlpIntegration
- 安装轻量版Sentry SDK和OpenTelemetry依赖:
bash
npm install @sentry/node-core @opentelemetry/api @opentelemetry/sdk-trace-node @opentelemetry/sdk-trace-base- 创建埋点文件(),同时配置OTel与Sentry:
instrument.mjs
javascript
import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
import * as Sentry from '@sentry/node-core/light';
import { otlpIntegration } from '@sentry/node-core/light/otlp';
const provider = new NodeTracerProvider();
provider.register();
Sentry.init({
dsn: '___PUBLIC_DSN___',
integrations: [
otlpIntegration({
collectorUrl: 'http://localhost:4318/v1/traces',
}),
],
});- 使用标志启动应用:
--import
bash
node --import ./instrument.mjs app.mjs使用Collector的实际OTLP HTTP端点。若在本地运行,默认值为。
http://localhost:4318/v1/traces使用时请勿设置otlpIntegration——采样由OTel控制,设置该值会与OTLP流程冲突。tracesSampleRate
Troubleshooting
故障排查
| Error | Cause | Fix |
|---|---|---|
| “failed to create project” | Missing Project:Write permission | Update Internal Integration permissions in Sentry |
| “no team found” | No teams in org | Create a team in Sentry before enabling auto-create |
| “invalid auth token” | Wrong token type or expired | Use Internal Integration token, not user auth token |
| “connection refused” on 4317/4318 | Collector not running or port conflict | Check collector logs and ensure ports are available |
| Validation fails with env var errors | .env file not loaded or placeholders not replaced | Ensure real credentials are in .env and the file is sourced |
| “container name already in use” | Previous container exists | Run |
| 错误 | 原因 | 修复方案 |
|---|---|---|
| “failed to create project” | 缺少项目写入权限 | 在Sentry中更新内部集成权限 |
| “no team found” | 组织中无团队 | 启用自动创建前,先在Sentry中创建团队 |
| “invalid auth token” | 令牌类型错误或已过期 | 使用内部集成令牌,而非用户认证令牌 |
| 4317/4318端口“connection refused” | Collector未运行或端口冲突 | 检查Collector日志,确保端口可用 |
| 验证时出现环境变量错误 | .env文件未加载或占位符未替换 | 确保.env文件包含真实凭证且已加载 |
| “container name already in use” | 存在旧容器 | 运行 |