Skip to content

Commit 837861f

Browse files
authored
[telemetrygen] support --service for all signal types (#38044)
This flag was supported only for traces. It's possible to set the service name via `--otlp-attributes`, but it's more convenient to be able to set it via `--service`. I added it to all signals, but if others disagree with this change, then I would suggest we remove it from all signals. --------- Signed-off-by: Alex Boten <[email protected]>
1 parent 099af17 commit 837861f

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: telemetrygen
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Support `--service` for all signal types, rather than just traces
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [38044]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: []

cmd/telemetrygen/internal/common/config.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"github.com/spf13/pflag"
1313
"go.opentelemetry.io/otel/attribute"
14+
semconv "go.opentelemetry.io/otel/semconv/v1.25.0"
1415
)
1516

1617
var (
@@ -72,6 +73,7 @@ type Config struct {
7273
HTTPPath string
7374
Headers KeyValue
7475
ResourceAttributes KeyValue
76+
ServiceName string
7577
TelemetryAttributes KeyValue
7678

7779
// OTLP TLS configuration
@@ -102,6 +104,8 @@ func (c *Config) Endpoint() string {
102104
func (c *Config) GetAttributes() []attribute.KeyValue {
103105
var attributes []attribute.KeyValue
104106

107+
// may be overridden by `--otlp-attributes service.name="foo"`
108+
attributes = append(attributes, semconv.ServiceNameKey.String(c.ServiceName))
105109
if len(c.ResourceAttributes) > 0 {
106110
for k, t := range c.ResourceAttributes {
107111
switch v := t.(type) {
@@ -158,6 +162,8 @@ func (c *Config) CommonFlags(fs *pflag.FlagSet) {
158162
fs.BoolVar(&c.InsecureSkipVerify, "otlp-insecure-skip-verify", c.InsecureSkipVerify, "Whether a client verifies the server's certificate chain and host name")
159163
fs.BoolVar(&c.UseHTTP, "otlp-http", c.UseHTTP, "Whether to use HTTP exporter rather than a gRPC one")
160164

165+
fs.StringVar(&c.ServiceName, "service", c.ServiceName, "Service name to use")
166+
161167
// custom headers
162168
fs.Var(&c.Headers, "otlp-header", "Custom header to be passed along with each OTLP request. The value is expected in the format key=\"value\". "+
163169
"Note you may need to escape the quotes when using the tool from a cli. "+
@@ -198,6 +204,7 @@ func (c *Config) SetDefaults() {
198204
c.HTTPPath = ""
199205
c.Headers = make(KeyValue)
200206
c.ResourceAttributes = make(KeyValue)
207+
c.ServiceName = "telemetrygen"
201208
c.TelemetryAttributes = make(KeyValue)
202209
c.CaFile = ""
203210
c.ClientAuth.Enabled = false

cmd/telemetrygen/pkg/traces/config.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ type Config struct {
1818
NumTraces int
1919
NumChildSpans int
2020
PropagateContext bool
21-
ServiceName string
2221
StatusCode string
2322
Batch bool
2423
LoadSize int
@@ -41,7 +40,6 @@ func (c *Config) Flags(fs *pflag.FlagSet) {
4140
fs.IntVar(&c.NumTraces, "traces", c.NumTraces, "Number of traces to generate in each worker (ignored if duration is provided)")
4241
fs.IntVar(&c.NumChildSpans, "child-spans", c.NumChildSpans, "Number of child spans to generate for each trace")
4342
fs.BoolVar(&c.PropagateContext, "marshal", c.PropagateContext, "Whether to marshal trace context via HTTP headers")
44-
fs.StringVar(&c.ServiceName, "service", c.ServiceName, "Service name to use")
4543
fs.StringVar(&c.StatusCode, "status-code", c.StatusCode, "Status code to use for the spans, one of (Unset, Error, Ok) or the equivalent integer (0,1,2)")
4644
fs.BoolVar(&c.Batch, "batch", c.Batch, "Whether to batch traces")
4745
fs.IntVar(&c.LoadSize, "size", c.LoadSize, "Desired minimum size in MB of string data for each trace generated. This can be used to test traces with large payloads, i.e. when testing the OTLP receiver endpoint max receive size.")
@@ -57,7 +55,6 @@ func (c *Config) SetDefaults() {
5755
c.NumTraces = 1
5856
c.NumChildSpans = 1
5957
c.PropagateContext = false
60-
c.ServiceName = "telemetrygen"
6158
c.StatusCode = "0"
6259
c.Batch = true
6360
c.LoadSize = 0

cmd/telemetrygen/pkg/traces/traces.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ func Start(cfg *Config) error {
8080
}
8181

8282
var attributes []attribute.KeyValue
83-
// may be overridden by `--otlp-attributes service.name="foo"`
84-
attributes = append(attributes, semconv.ServiceNameKey.String(cfg.ServiceName))
8583
attributes = append(attributes, cfg.GetAttributes()...)
8684

8785
tracerProvider := sdktrace.NewTracerProvider(

0 commit comments

Comments
 (0)