Skip to content

Commit 490fd7f

Browse files
itssaharshdashpoledmathieu
authored
Checked if Instrument Enabled before measuring in otlpgrpc (#7824)
This pr updates otlploggprc for cecking if the operation is enabled before addinng any metric or performing operation. tracked in #7800 --------- Co-authored-by: David Ashpole <dashpole@google.com> Co-authored-by: Damien Mathieu <42@dmathieu.com>
1 parent 53c10af commit 490fd7f

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

exporters/otlp/otlplog/otlploggrpc/internal/observ/instrumentation.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,12 @@ func NewInstrumentation(id int64, target string) (*Instrumentation, error) {
161161
// ExportLogs method returns.
162162
func (i *Instrumentation) ExportLogs(ctx context.Context, count int64) ExportOp {
163163
start := time.Now()
164-
addOpt := get[metric.AddOption](addOpPool)
165-
defer put(addOpPool, addOpt)
166-
167-
*addOpt = append(*addOpt, i.addOpt)
168-
169-
i.logInflightMetric.Add(ctx, count, *addOpt...)
164+
if i.logInflightMetric.Enabled(ctx) {
165+
addOpt := get[metric.AddOption](addOpPool)
166+
defer put(addOpPool, addOpt)
167+
*addOpt = append(*addOpt, i.addOpt)
168+
i.logInflightMetric.Add(ctx, count, *addOpt...)
169+
}
170170

171171
return ExportOp{
172172
nLogs: count,
@@ -198,11 +198,14 @@ func (e ExportOp) End(err error) {
198198
defer put(addOpPool, addOpt)
199199
*addOpt = append(*addOpt, e.inst.addOpt)
200200

201-
e.inst.logInflightMetric.Add(e.ctx, -e.nLogs, *addOpt...)
201+
if e.inst.logInflightMetric.Enabled(e.ctx) {
202+
e.inst.logInflightMetric.Add(e.ctx, -e.nLogs, *addOpt...)
203+
}
202204
success := successful(e.nLogs, err)
203-
e.inst.logExportedMetric.Add(e.ctx, success, *addOpt...)
204-
205-
if err != nil {
205+
if e.inst.logExportedMetric.Enabled(e.ctx) {
206+
e.inst.logExportedMetric.Add(e.ctx, success, *addOpt...)
207+
}
208+
if err != nil && e.inst.logExportedMetric.Enabled(e.ctx) {
206209
// Add the error.type attribute to the attribute set.
207210
attrs := get[attribute.KeyValue](attrsPool)
208211
defer put(attrsPool, attrs)

0 commit comments

Comments
 (0)