github.com/waldiirawan/apm-agent-go/v2@v2.2.2/apmtest/discard.go (about)

     1  // Licensed to Elasticsearch B.V. under one or more contributor
     2  // license agreements. See the NOTICE file distributed with
     3  // this work for additional information regarding copyright
     4  // ownership. Elasticsearch B.V. licenses this file to you under
     5  // the Apache License, Version 2.0 (the "License"); you may
     6  // not use this file except in compliance with the License.
     7  // You may obtain a copy of the License at
     8  //
     9  //     http://www.apache.org/licenses/LICENSE-2.0
    10  //
    11  // Unless required by applicable law or agreed to in writing,
    12  // software distributed under the License is distributed on an
    13  // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    14  // KIND, either express or implied.  See the License for the
    15  // specific language governing permissions and limitations
    16  // under the License.
    17  
    18  package apmtest // import "github.com/waldiirawan/apm-agent-go/v2/apmtest"
    19  
    20  import (
    21  	"log"
    22  
    23  	"github.com/waldiirawan/apm-agent-go/v2"
    24  	"github.com/waldiirawan/apm-agent-go/v2/transport/transporttest"
    25  )
    26  
    27  // DiscardTracer is an apm.Tracer that discards all events.
    28  //
    29  // This tracer may be used by multiple tests, and so should
    30  // not be modified or closed.
    31  //
    32  // Importing apmttest will close apm.DefaultTracer, and update
    33  // it to this value.
    34  var DiscardTracer *apm.Tracer
    35  
    36  // NewDiscardTracer returns a new apm.Tracer that discards all events.
    37  func NewDiscardTracer() *apm.Tracer {
    38  	tracer, err := apm.NewTracerOptions(apm.TracerOptions{
    39  		Transport: transporttest.Discard,
    40  	})
    41  	if err != nil {
    42  		log.Fatal(err)
    43  	}
    44  	return tracer
    45  }
    46  
    47  func init() {
    48  	tracer := NewDiscardTracer()
    49  	DiscardTracer = tracer
    50  	apm.SetDefaultTracer(DiscardTracer)
    51  }