Skip to content

Commit 034a66d

Browse files
committed
introduce otelgen tool for OTLP endpoints
1 parent af57e24 commit 034a66d

File tree

8 files changed

+448
-2
lines changed

8 files changed

+448
-2
lines changed

.dockerignore

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Binaries
2+
otelgen
3+
*.exe
4+
*.dll
5+
*.so
6+
*.dylib
7+
8+
# Test files
9+
*.test
10+
*_test.go
11+
12+
# Git
13+
.git
14+
.gitignore
15+
16+
# Documentation
17+
README.md
18+
19+
# IDE
20+
.vscode
21+
.idea
22+
*.swp
23+
*.swo
24+
*~
25+
26+
# CI/CD
27+
.github
28+
.gitlab-ci.yml
29+
30+
# Claude
31+
.claude

.github/workflows/docker-build.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Build and Push Docker Image
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
tags:
8+
- 'v*'
9+
10+
env:
11+
REGISTRY: ghcr.io
12+
IMAGE_NAME: ${{ github.repository }}
13+
14+
jobs:
15+
build-and-push:
16+
runs-on: ubuntu-latest
17+
permissions:
18+
contents: read
19+
packages: write
20+
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@v4
24+
25+
- name: Set up Docker Buildx
26+
uses: docker/setup-buildx-action@v3
27+
28+
- name: Log in to Container Registry
29+
uses: docker/login-action@v3
30+
with:
31+
registry: ${{ env.REGISTRY }}
32+
username: ${{ github.actor }}
33+
password: ${{ secrets.GITHUB_TOKEN }}
34+
35+
- name: Extract metadata (tags, labels)
36+
id: meta
37+
uses: docker/metadata-action@v5
38+
with:
39+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
40+
tags: |
41+
type=ref,event=branch
42+
type=ref,event=pr
43+
type=semver,pattern={{version}}
44+
type=semver,pattern={{major}}.{{minor}}
45+
type=semver,pattern={{major}}
46+
type=raw,value=latest,enable={{is_default_branch}}
47+
48+
- name: Build and push Docker image
49+
uses: docker/build-push-action@v5
50+
with:
51+
context: .
52+
push: true
53+
tags: ${{ steps.meta.outputs.tags }}
54+
labels: ${{ steps.meta.outputs.labels }}
55+
cache-from: type=gha
56+
cache-to: type=gha,mode=max
57+
platforms: linux/amd64,linux/arm64

.gitignore

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Binaries
2+
otelgen
3+
*.exe
4+
*.dll
5+
*.so
6+
*.dylib
7+
8+
# Test binary, built with `go test -c`
9+
*.test
10+
11+
# Output of the go coverage tool
12+
*.out
13+
14+
# Dependency directories
15+
vendor/
16+
17+
# Go workspace file
18+
go.work
19+
20+
# IDE and editor files
21+
.claude
22+
.vscode
23+
.idea
24+
*.swp
25+
*.swo
26+
*~

Dockerfile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
FROM golang:1.21-alpine AS builder
2+
3+
WORKDIR /build
4+
5+
# Copy go mod files
6+
COPY go.mod go.sum ./
7+
8+
# Download dependencies
9+
RUN go mod download
10+
11+
# Copy source code
12+
COPY cmd/ ./cmd/
13+
COPY pkg/ ./pkg/
14+
15+
# Build static binary
16+
RUN CGO_ENABLED=0 GOOS=linux go build \
17+
-trimpath \
18+
-ldflags='-w -s -extldflags "-static"' \
19+
-o otelgen ./cmd/otelgen
20+
21+
# Final stage - use scratch for minimal image
22+
FROM scratch
23+
24+
# Copy CA certificates for TLS
25+
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
26+
27+
# Copy the binary
28+
COPY --from=builder /build/otelgen /otelgen
29+
30+
ENTRYPOINT ["/otelgen"]

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 EdgeDelta, Inc.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 173 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,173 @@
1-
# otelgen
2-
Simple, reliable CLI tool for generating OpenTelemetry traces, metrics, and logs to test OTLP endpoints
1+
# Telemetrygen
2+
3+
A simple and reliable CLI tool for generating OpenTelemetry traces, metrics, and logs to test OTLP endpoints.
4+
5+
## Features
6+
7+
- Generate traces, metrics, and logs
8+
- Support for gRPC, gRPCs, HTTP, and HTTPS protocols
9+
- Automatic port selection (4317 for gRPC, 4318 for HTTP)
10+
- Configurable rate and duration
11+
- Simple and intuitive CLI interface
12+
13+
## Installation
14+
15+
### Build from source
16+
17+
```bash
18+
go build -o telemetrygen
19+
```
20+
21+
### Build Docker image
22+
23+
```bash
24+
docker build -t telemetrygen .
25+
```
26+
27+
The Docker image uses a multi-stage build with `scratch` as the final base image for minimal size (~20MB).
28+
29+
## Usage
30+
31+
### Traces
32+
33+
Generate trace data:
34+
35+
```bash
36+
# Using gRPCs (secure gRPC)
37+
./telemetrygen traces \
38+
--otlp-endpoint grpcs://852e95f4-5bbc-4d54-9879-b8591ff6194c-grpc-us-west2-cf.aws-staging.edgedelta.com:4317 \
39+
--service my-service \
40+
--rate 1 \
41+
--duration 10s
42+
43+
# Using HTTP
44+
./telemetrygen traces \
45+
--otlp-endpoint http://localhost:4318 \
46+
--service my-service \
47+
--rate 10 \
48+
--duration 1m
49+
50+
# Port is optional - will use default 4317 for gRPC
51+
./telemetrygen traces \
52+
--otlp-endpoint grpc://localhost \
53+
--service my-service
54+
```
55+
56+
### Metrics
57+
58+
Generate metrics data:
59+
60+
```bash
61+
# Using gRPCs
62+
./telemetrygen metrics \
63+
--otlp-endpoint grpcs://852e95f4-5bbc-4d54-9879-b8591ff6194c-grpc-us-west2-cf.aws-staging.edgedelta.com:4317 \
64+
--service my-service \
65+
--rate 1 \
66+
--duration 10s
67+
68+
# Using HTTPS
69+
./telemetrygen metrics \
70+
--otlp-endpoint https://localhost:4318 \
71+
--service my-service \
72+
--rate 5 \
73+
--duration 30s
74+
```
75+
76+
### Logs
77+
78+
Generate log data:
79+
80+
```bash
81+
# Using gRPCs
82+
./telemetrygen logs \
83+
--otlp-endpoint grpcs://852e95f4-5bbc-4d54-9879-b8591ff6194c-grpc-us-west2-cf.aws-staging.edgedelta.com:4317 \
84+
--service my-service \
85+
--rate 1 \
86+
--duration 10s
87+
88+
# Using HTTP with custom port
89+
./telemetrygen logs \
90+
--otlp-endpoint http://localhost:8080 \
91+
--service my-service \
92+
--rate 20 \
93+
--duration 5s
94+
```
95+
96+
## Docker Usage
97+
98+
```bash
99+
# Traces
100+
docker run --rm telemetrygen traces \
101+
--otlp-endpoint grpcs://your-endpoint:4317 \
102+
--service my-service \
103+
--rate 1 \
104+
--duration 10s
105+
106+
# Metrics
107+
docker run --rm telemetrygen metrics \
108+
--otlp-endpoint grpcs://your-endpoint:4317 \
109+
--service my-service \
110+
--rate 1 \
111+
--duration 10s
112+
113+
# Logs
114+
docker run --rm telemetrygen logs \
115+
--otlp-endpoint grpcs://your-endpoint:4317 \
116+
--service my-service \
117+
--rate 1 \
118+
--duration 10s
119+
```
120+
121+
## Flags
122+
123+
| Flag | Description | Default | Required |
124+
|------|-------------|---------|----------|
125+
| `--otlp-endpoint` | OTLP endpoint URL (grpc://, grpcs://, http://, https://) | - | Yes |
126+
| `--service` | Service name for telemetry | telemetrygen | No |
127+
| `--rate` | Number of telemetry items per second | 1 | No |
128+
| `--duration` | How long to generate telemetry (e.g., 10s, 1m, 1h) | 10s | No |
129+
| `--insecure` | Use insecure connection (not implemented yet) | false | No |
130+
131+
## Protocol Support
132+
133+
- `grpc://` - Insecure gRPC (default port: 4317)
134+
- `grpcs://` - Secure gRPC with TLS (default port: 4317)
135+
- `http://` - Insecure HTTP (default port: 4318)
136+
- `https://` - Secure HTTP with TLS (default port: 4318)
137+
138+
## Default Ports
139+
140+
If you don't specify a port in the endpoint URL, the following defaults are used:
141+
142+
- gRPC/gRPCs: 4317
143+
- HTTP/HTTPS: 4318
144+
145+
## Examples
146+
147+
```bash
148+
# Quick test with local collector
149+
./telemetrygen traces --otlp-endpoint grpc://localhost --service test-app --duration 5s
150+
151+
# High-volume test
152+
./telemetrygen metrics --otlp-endpoint http://localhost:4318 --service load-test --rate 100 --duration 1m
153+
154+
# Production endpoint test
155+
./telemetrygen logs --otlp-endpoint grpcs://prod.example.com:4317 --service prod-app --rate 10 --duration 30s
156+
```
157+
158+
## What Gets Generated
159+
160+
### Traces
161+
- Parent spans with child spans
162+
- Random operation types and IDs
163+
- Realistic timing and nesting
164+
165+
### Metrics
166+
- Counter: `telemetrygen.requests`
167+
- Histogram: `telemetrygen.duration`
168+
- Gauge: `telemetrygen.cpu_usage`
169+
170+
### Logs
171+
- Various log levels (INFO, WARN, ERROR, DEBUG)
172+
- Realistic log messages
173+
- Additional attributes (component, request_id, user_id)

go.mod

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
module github.com/edgedelta/otelgen
2+
3+
go 1.21
4+
5+
require (
6+
github.com/spf13/cobra v1.8.0
7+
go.opentelemetry.io/otel v1.24.0
8+
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.24.0
9+
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.24.0
10+
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.24.0
11+
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.24.0
12+
go.opentelemetry.io/otel/metric v1.24.0
13+
go.opentelemetry.io/otel/sdk v1.24.0
14+
go.opentelemetry.io/otel/sdk/metric v1.24.0
15+
go.opentelemetry.io/otel/trace v1.24.0
16+
google.golang.org/grpc v1.62.0
17+
)
18+
19+
require (
20+
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
21+
github.com/go-logr/logr v1.4.1 // indirect
22+
github.com/go-logr/stdr v1.2.2 // indirect
23+
github.com/golang/protobuf v1.5.3 // indirect
24+
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.0 // indirect
25+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
26+
github.com/spf13/pflag v1.0.5 // indirect
27+
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.24.0 // indirect
28+
go.opentelemetry.io/proto/otlp v1.1.0 // indirect
29+
golang.org/x/net v0.20.0 // indirect
30+
golang.org/x/sys v0.17.0 // indirect
31+
golang.org/x/text v0.14.0 // indirect
32+
google.golang.org/genproto/googleapis/api v0.0.0-20240123012728-ef4313101c80 // indirect
33+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80 // indirect
34+
google.golang.org/protobuf v1.32.0 // indirect
35+
)

0 commit comments

Comments
 (0)