Skip to content

Commit f46759e

Browse files
committed
[trace explorer] update docs to include trace explorer information
1 parent 9db3779 commit f46759e

File tree

3 files changed

+198
-13
lines changed

3 files changed

+198
-13
lines changed

docs.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,12 @@
272272
"pages": [
273273
"infra-analytics/overview",
274274
"infra-analytics/getting-started",
275+
{
276+
"group": "Trace Explorer",
277+
"pages": [
278+
"infra-analytics/send-traces"
279+
]
280+
},
275281
{
276282
"group": "Logs Explorer",
277283
"pages": [
@@ -1056,7 +1062,8 @@
10561062
{
10571063
"group": "Open Telemetry",
10581064
"pages": [
1059-
"/infra-analytics/getting-started"
1065+
"/infra-analytics/getting-started",
1066+
"/infra-analytics/send-traces"
10601067
]
10611068
},
10621069
"server/concepts/cloudflare",
@@ -1829,4 +1836,4 @@
18291836
"slack": "https://statsig.com/slack"
18301837
}
18311838
}
1832-
}
1839+
}

infra-analytics/getting-started.mdx

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,22 @@ This guide helps you setup and send OpenTelemetry telemetry to Statsig so you ca
88

99
There are two common paths:
1010
- Kubernetes/OpenTelemetry Collector: scrape logs and metrics from your cluster and export to Statsig. See [Open Telemetry Logs and Metrics](/server/concepts/open_telemetry) for a more complete guide.
11-
- Applications: export traces, metrics, and logs directly from your app over OTLP/HTTP to Statsig or to your collector. See the quick starts below.
11+
- Applications: export traces, metrics, and logs to your OpenTelemetry Collector (or traces directly from TypeScript/Node). See the quick starts below.
1212

1313
<Info>
1414
**Endpoint & Auth**
1515
- Endpoint: `https://api.statsig.com/otlp`
1616
- Auth header: `statsig-api-key: <your Server SDK Secret key>`
1717
</Info>
1818

19+
<Info>
20+
Direct trace export to the Statsig OTLP endpoint is only available for TypeScript/Node. For all other languages, send traces to your OpenTelemetry Collector and forward from the Collector to Statsig over OTLP/HTTP.
21+
</Info>
22+
23+
<Info>
24+
Need a deeper setup guide? See [Open Telemetry Logs and Metrics](/server/concepts/open_telemetry) for collector installation/config, and the [Trace Explorer quick start](/infra-analytics/send-traces) for language-specific trace examples.
25+
</Info>
26+
1927
---
2028
## Application Telemetry quick starts
2129

@@ -64,11 +72,12 @@ const sdk = new NodeSDK({
6472
[ATTR_SERVICE_VERSION]: process.env.VERSION || '1',
6573
env: process.env.NODE_ENV || 'development',
6674
}),
67-
// Optional: enable traces if you want to try out tracing
68-
// traceExporter: new OTLPTraceExporter({
69-
// url: 'https://api.statsig.com/otlp/v1/traces',
70-
// headers,
71-
// }),
75+
traceExporter: new OTLPTraceExporter({
76+
url: 'https://api.statsig.com/otlp/v1/traces',
77+
// or
78+
// url: <your-collector-endpoint>/v1/metrics
79+
headers,
80+
}),
7281
metricReader: new PeriodicExportingMetricReader({
7382
exporter: new OTLPMetricExporter({
7483
url: 'https://api.statsig.com/otlp/v1/metrics',
@@ -200,11 +209,12 @@ export async function register() {
200209
[ATTR_SERVICE_VERSION]: process.env.VERSION || '1',
201210
env: process.env.NODE_ENV || 'development',
202211
}),
203-
// Optional: enable traces if you want to try out tracing
204-
// traceExporter: new OTLPTraceExporter({
205-
// url: 'https://api.statsig.com/otlp/v1/traces',
206-
// headers,
207-
// }),
212+
traceExporter: new OTLPTraceExporter({
213+
url: 'https://api.statsig.com/otlp/v1/traces',
214+
// or
215+
// url: <your-collector-endpoint>/v1/metrics
216+
headers,
217+
}),
208218
metricReader: new PeriodicExportingMetricReader({
209219
exporter: new OTLPMetricExporter({
210220
url: 'https://api.statsig.com/otlp/v1/metrics',

infra-analytics/send-traces.mdx

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
---
2+
title: Trace Explorer Quick Start
3+
sidebarTitle: Quick Start
4+
description: Minimal OTLP/HTTP examples for exporting traces to Statsig's Trace Explorer across popular languages.
5+
---
6+
7+
8+
<Info>
9+
Want Logs and Metrics too? See [Getting Started](/infra-analytics/getting-started) for more in-depth OpenTelemetry Collector setup instructions.
10+
</Info>
11+
12+
13+
Use the OTLP/HTTP traces endpoint to forward spans into Trace Explorer. Authenticate with your Server Secret key in the header:
14+
15+
- Endpoint: `https://api.statsig.com/otlp/v1/traces`
16+
- Header: `statsig-api-key: <your Server SDK Secret key>`
17+
18+
19+
Note: Direct to API is currently supported for TypeScript/Node only. For all other languages, send traces to your OpenTelemetry Collector and configure it to forward to Statsig over OTLP/HTTP.
20+
21+
Point non-TypeScript apps to your Collector (for example `http://localhost:4318/v1/traces`) and configure the Collector to forward to Statsig:
22+
23+
```yaml title="collector.yaml"
24+
receivers:
25+
otlp:
26+
protocols:
27+
http:
28+
29+
exporters:
30+
otlphttp:
31+
endpoint: https://api.statsig.com/otlp
32+
encoding: json
33+
headers:
34+
statsig-api-key: ${env:STATSIG_SERVER_SDK_SECRET}
35+
36+
service:
37+
pipelines:
38+
traces:
39+
receivers: [otlp]
40+
exporters: [otlphttp]
41+
```
42+
43+
<Tabs>
44+
<Tab title="TypeScript/Node">
45+
46+
```bash
47+
npm install @opentelemetry/sdk-node @opentelemetry/sdk-trace-node @opentelemetry/sdk-trace-base @opentelemetry/exporter-trace-otlp-http @opentelemetry/resources @opentelemetry/semantic-conventions @opentelemetry/api
48+
```
49+
50+
```js
51+
// trace.js
52+
const { NodeSDK } = require('@opentelemetry/sdk-node');
53+
const { OTLPTraceExporter } = require('@opentelemetry/exporter-trace-otlp-http');
54+
const { BatchSpanProcessor } = require('@opentelemetry/sdk-trace-base');
55+
const { Resource } = require('@opentelemetry/resources');
56+
const { SemanticResourceAttributes } = require('@opentelemetry/semantic-conventions');
57+
const { trace } = require('@opentelemetry/api');
58+
59+
const sdk = new NodeSDK({
60+
resource: new Resource({
61+
[SemanticResourceAttributes.SERVICE_NAME]: 'trace-sample-node',
62+
}),
63+
spanProcessor: new BatchSpanProcessor(
64+
new OTLPTraceExporter({
65+
url: 'https://api.statsig.com/otlp/v1/traces',
66+
headers: { 'statsig-api-key': process.env.STATSIG_SERVER_SDK_SECRET || '' },
67+
}),
68+
),
69+
});
70+
71+
sdk.start().then(() => {
72+
const tracer = trace.getTracer('example');
73+
const span = tracer.startSpan('do-work');
74+
span.setAttribute('example', true);
75+
span.end();
76+
77+
setTimeout(() => sdk.shutdown(), 1000);
78+
});
79+
```
80+
</Tab>
81+
<Tab title="Python">
82+
83+
```bash
84+
pip install opentelemetry-sdk opentelemetry-exporter-otlp-proto-http
85+
```
86+
87+
```python
88+
# trace.py
89+
from opentelemetry import trace
90+
from opentelemetry.sdk.resources import Resource
91+
from opentelemetry.sdk.trace import TracerProvider
92+
from opentelemetry.sdk.trace.export import BatchSpanProcessor
93+
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
94+
95+
trace.set_tracer_provider(
96+
TracerProvider(resource=Resource.create({"service.name": "trace-sample-python"}))
97+
)
98+
99+
exporter = OTLPSpanExporter(
100+
endpoint="http://localhost:4318/v1/traces", # your Collector
101+
)
102+
trace.get_tracer_provider().add_span_processor(BatchSpanProcessor(exporter))
103+
104+
tracer = trace.get_tracer(__name__)
105+
with tracer.start_as_current_span("do-work") as span:
106+
span.set_attribute("example", True)
107+
108+
trace.get_tracer_provider().shutdown()
109+
```
110+
</Tab>
111+
<Tab title="Go">
112+
113+
```bash
114+
go get go.opentelemetry.io/otel/sdk go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp go.opentelemetry.io/otel/semconv/v1.26.0
115+
```
116+
117+
```go
118+
// main.go
119+
package main
120+
121+
import (
122+
"context"
123+
"log"
124+
125+
"go.opentelemetry.io/otel"
126+
"go.opentelemetry.io/otel/attribute"
127+
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp"
128+
"go.opentelemetry.io/otel/sdk/resource"
129+
sdktrace "go.opentelemetry.io/otel/sdk/trace"
130+
semconv "go.opentelemetry.io/otel/semconv/v1.26.0"
131+
)
132+
133+
func main() {
134+
ctx := context.Background()
135+
136+
exporter, err := otlptracehttp.New(ctx,
137+
otlptracehttp.WithEndpointURL("http://localhost:4318/v1/traces"), // your Collector
138+
)
139+
if err != nil {
140+
log.Fatal(err)
141+
}
142+
143+
tp := sdktrace.NewTracerProvider(
144+
sdktrace.WithBatcher(exporter),
145+
sdktrace.WithResource(resource.NewWithAttributes(
146+
semconv.SchemaURL,
147+
semconv.ServiceNameKey.String("trace-sample-go"),
148+
)),
149+
)
150+
otel.SetTracerProvider(tp)
151+
152+
tracer := otel.Tracer("example")
153+
ctx, span := tracer.Start(ctx, "do-work")
154+
span.SetAttributes(attribute.Bool("example", true))
155+
span.End()
156+
157+
_ = tp.Shutdown(ctx)
158+
}
159+
```
160+
</Tab>
161+
</Tabs>
162+
163+
164+
<Info>
165+
Need a deeper setup guide? See [Open Telemetry Logs and Metrics](/server/concepts/open_telemetry) for collector installation/config,
166+
and if you want Logs and Metrics too? See [Getting Started](/infra-analytics/getting-started) for
167+
more in-depth OpenTelemetry Collector setup instructions.
168+
</Info>

0 commit comments

Comments
 (0)