Skip to content

Commit bb075a7

Browse files
committed
Propagate telemetry.resource to the internal logs. open-telemetry#12582
Signed-off-by: Israel Blancas <[email protected]>
1 parent 8cf42f3 commit bb075a7

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
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: bug_fix
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
7+
component: "internal telemetry"
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: "Add resource attributes from telemetry.resource to the logger"
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [12582]
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+
Resource attributes from telemetry.resource were not added to the internal
20+
logs but to metrics and traces. This fix ensures they are added to the logs.
21+
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: []

service/telemetry/logger.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ func newLogger(set Settings, cfg Config) (*zap.Logger, log.LoggerProvider, error
3737
return nil, nil, err
3838
}
3939

40+
fields := []zap.Field{}
41+
for k, v := range cfg.Resource {
42+
if v != nil {
43+
f := zap.Field{Key: k, Type: zapcore.StringType, String: *v}
44+
fields = append(fields, f)
45+
}
46+
}
47+
logger = logger.With(fields...)
48+
4049
var lp log.LoggerProvider
4150

4251
if len(cfg.Logs.Processors) > 0 && set.SDK != nil {
@@ -52,6 +61,10 @@ func newLogger(set Settings, cfg Config) (*zap.Logger, log.LoggerProvider, error
5261
if err != nil {
5362
panic(err)
5463
}
64+
65+
// Adding the fields to the logger ensures they are shown in the collector
66+
// logs but they are not propagated to the core. We need to add them
67+
core.With(fields)
5568
return core
5669
}))
5770
}

0 commit comments

Comments
 (0)