Skip to content

Commit d678dd7

Browse files
odubajDTedmocostaTylerHelmuthevan-bradley
authored
[pkg/ottl] add MarshalLogObject to ottlmetric context (#38293)
<!-- Issue number (e.g. #1234) or full URL to issue, if applicable. --> #### Link to tracking issue Fixes #38103 --------- Signed-off-by: odubajDT <[email protected]> Co-authored-by: Edmo Vamerlatti Costa <[email protected]> Co-authored-by: Tyler Helmuth <[email protected]> Co-authored-by: Evan Bradley <[email protected]>
1 parent 00ca069 commit d678dd7

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-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. filelogreceiver)
7+
component: pkg/ottl
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: "Change the `ottlmetric` context to properly display the `TransformContext` value in debug logs"
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: [38103]
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: []

pkg/ottl/contexts/ottlmetric/metrics.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
package ottlmetric // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottlmetric"
55

66
import (
7+
"errors"
78
"fmt"
89

910
"go.opentelemetry.io/collector/component"
1011
"go.opentelemetry.io/collector/pdata/pcommon"
1112
"go.opentelemetry.io/collector/pdata/pmetric"
13+
"go.uber.org/zap/zapcore"
1214

1315
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl"
1416
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxcache"
@@ -17,6 +19,7 @@ import (
1719
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxmetric"
1820
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxresource"
1921
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/ctxscope"
22+
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/logging"
2023
)
2124

2225
// Experimental: *NOTE* this constant is subject to change or removal in the future.
@@ -38,6 +41,15 @@ type TransformContext struct {
3841
resourceMetrics pmetric.ResourceMetrics
3942
}
4043

44+
func (tCtx TransformContext) MarshalLogObject(encoder zapcore.ObjectEncoder) error {
45+
err := encoder.AddObject("resource", logging.Resource(tCtx.resource))
46+
err = errors.Join(err, encoder.AddObject("scope", logging.InstrumentationScope(tCtx.instrumentationScope)))
47+
err = errors.Join(err, encoder.AddObject("metric", logging.Metric(tCtx.metric)))
48+
err = errors.Join(err, encoder.AddObject("cache", logging.Map(tCtx.cache)))
49+
50+
return err
51+
}
52+
4153
type TransformContextOption func(*TransformContext)
4254

4355
func NewTransformContext(metric pmetric.Metric, metrics pmetric.MetricSlice, instrumentationScope pcommon.InstrumentationScope, resource pcommon.Resource, scopeMetrics pmetric.ScopeMetrics, resourceMetrics pmetric.ResourceMetrics, options ...TransformContextOption) TransformContext {

0 commit comments

Comments
 (0)