github.com/newrelic/go-agent@v3.26.0+incompatible/_integrations/nrstan/nrstan_doc.go (about)

     1  // Copyright 2020 New Relic Corporation. All rights reserved.
     2  // SPDX-License-Identifier: Apache-2.0
     3  
     4  // Package nrstan instruments https://github.com/nats-io/stan.go.
     5  //
     6  // This package can be used to simplify instrumenting NATS Streaming subscribers. Currently due to the nature of
     7  // the NATS Streaming framework we are limited to two integration points: `StartPublishSegment` for publishers, and
     8  // `SubWrapper` for subscribers.
     9  //
    10  //
    11  // NATS Streaming subscribers
    12  //
    13  // `nrstan.StreamingSubWrapper` can be used to wrap the function for STREAMING stan.Subscribe and stan.QueueSubscribe
    14  // (https://godoc.org/github.com/nats-io/stan.go#Conn) If the `newrelic.Application` parameter is non-nil, it will
    15  // create a `newrelic.Transaction` and end the transaction when the passed function is complete. Example:
    16  //
    17  //	sc, err := stan.Connect(clusterName, clientName)
    18  //	if err != nil {
    19  // 		t.Fatal("Couldn't connect to server", err)
    20  //	}
    21  //	defer sc.Close()
    22  //	app := createTestApp(t)  // newrelic.Application
    23  //	sc.Subscribe(subject, StreamingSubWrapper(app, myMessageHandler)
    24  //
    25  //
    26  // NATS Streaming publishers
    27  //
    28  // You can use `nrnats.StartPublishSegment` from the `nrnats` package
    29  // (https://godoc.org/github.com/newrelic/go-agent/_integrations/nrnats/#StartPublishSegment)
    30  // to start an external segment when doing a streaming publish, which must be ended after publishing is complete.
    31  // Example:
    32  //
    33  //	sc, err := stan.Connect(clusterName, clientName)
    34  //	if err != nil {
    35  //		t.Fatal("Couldn't connect to server", err)
    36  //	}
    37  //	txn := currentTransaction()  // current newrelic.Transaction
    38  //	seg := nrnats.StartPublishSegment(txn, sc.NatsConn(), subj)
    39  //	sc.Publish(subj, []byte("Hello World"))
    40  //	seg.End()
    41  //
    42  // Full Publisher/Subscriber example:
    43  // https://github.com/newrelic/go-agent/blob/master/_integrations/nrstan/examples/main.go
    44  package nrstan
    45  
    46  import "github.com/newrelic/go-agent/internal"
    47  
    48  func init() { internal.TrackUsage("integration", "framework", "stan") }