- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1.8k
Add option to disable redundant 132B in log lines #14050
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Yaten <[email protected]>
| // If false, resource attributes neither be added to logs exported through the LoggerProvider nor | ||
| // to the logs written to stdout/stderr. | ||
| // (default = true) | ||
| ResourceAsZapFields bool `mapstructure:"resource_as_zap_field"` | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure where implementation specific things should go. @open-telemetry/collector-approvers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you kindly elaborate on this, wasn't able to get it completely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, if you were saying for this comment - #13869 (comment) ?
Signed-off-by: Yaten <[email protected]>
| There're some failing tests, working on the fix. By the time, I've converted this to draft 👍 | 
| @jade-guiton-dd , wanted to ask here, that currently,  {
			name: "auto-populated fields only",
			buildInfo: component.BuildInfo{
				Command: "mycommand",
				Version: "1.0.0",
			},
			resourceConfig: map[string]*string{},
			wantFields: map[string]string{
				string(semconv.ServiceNameKey):       "mycommand",
				string(semconv.ServiceVersionKey):    "1.0.0",
				string(semconv.ServiceInstanceIDKey): "",
			},
			cfg: &Config{
				Logs: LogsConfig{
					Level:               zapcore.InfoLevel,
					Encoding:            "json",
					ResourceAsZapFields: true,
				},
				Resource: map[string]*string{},
			},
		},Then, it'll work fine, but, it's not working if I don't add this field -  | 
| The default configuration for the telemetry factory is in  | 
Signed-off-by: Yaten <[email protected]>
| @jade-guiton-dd , I've added the required field in the  In short, the as far as I've observed here is that, this -  | 
| I didn't fully understand your comment, but let me try to explain. The way defaults are normally handled in the Collector is as follows: 1. the  In tests however, we need to perform this logic manually. If you pass in a config struct to a component, and a field is not specified, that field will default to its zero value, as is normal in Go; the value of that field in  This means that the existing test cases in  As for  | 
Signed-off-by: Yaten <[email protected]>
| Got this, thanks for explaining @jade-guiton-dd :) | 
| Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@           Coverage Diff           @@
##             main   #14050   +/-   ##
=======================================
  Coverage   92.27%   92.27%           
=======================================
  Files         657      657           
  Lines       41093    41094    +1     
=======================================
+ Hits        37917    37918    +1     
  Misses       2174     2174           
  Partials     1002     1002           ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
 | 
Signed-off-by: Yaten <[email protected]>
…ourceAttributes Signed-off-by: Yaten <[email protected]>
…er testing Signed-off-by: Yaten <[email protected]>
| I think there're some tests failing because of my latest commit, checking those 👀 | 
| The contrib-tests are failing for everyone, it's not related to your PR | 
| Ok, got this 👍 | 
| Yes, I think that's the best option. | 
| var cfg *Config | ||
| if tt.cfg == nil { | ||
| cfg = &Config{ | ||
| Logs: LogsConfig{ | ||
| Level: zapcore.InfoLevel, | ||
| Encoding: "json", | ||
| DisableResourceAttributes: false, | ||
| }, | ||
| Resource: tt.resourceConfig, | ||
| } | ||
| } else { | ||
| cfg = tt.cfg | ||
| cfg.Logs.DisableResourceAttributes = true | ||
| } | ||
|  | ||
| if tt.resourceConfig != nil { | ||
| cfg.Resource = tt.resourceConfig | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest something like:
| var cfg *Config | |
| if tt.cfg == nil { | |
| cfg = &Config{ | |
| Logs: LogsConfig{ | |
| Level: zapcore.InfoLevel, | |
| Encoding: "json", | |
| DisableResourceAttributes: false, | |
| }, | |
| Resource: tt.resourceConfig, | |
| } | |
| } else { | |
| cfg = tt.cfg | |
| cfg.Logs.DisableResourceAttributes = true | |
| } | |
| if tt.resourceConfig != nil { | |
| cfg.Resource = tt.resourceConfig | |
| cfg := &Config{ | |
| Logs: LogsConfig{ | |
| Level: zapcore.InfoLevel, | |
| Encoding: "json", | |
| }, | |
| Resource: tt.resourceConfig, | |
| } | |
| if tt.setConfig != nil { | |
| tt.setConfig(cfg) | 
and then in the test case have:
setConfig: func(cfg *Config) {
	cfg.Logs.DisableResourceAttributes = true
}
Description
This PR adds an option to disable the resource attribute in logs.
Link to tracking issue
Fixes #13869
Testing
Added unit tests in -
TestCreateLogger().