Skip to content

Commit

Permalink
AMQP Automatic Instrumentation
Browse files Browse the repository at this point in the history
Automatically instrument and collect distributed traces on AMQP/RabbitMQ
code with the New Relic Go agent.
  • Loading branch information
iamemilio committed Aug 29, 2023
1 parent d7809f3 commit e3d6c12
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
18 changes: 18 additions & 0 deletions v3/integrations/nramqp/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module github.com/newrelic/go-agent/v3/integrations/nramqp

go 1.21.0

require (
github.com/newrelic/go-agent/v3 v3.24.1
github.com/rabbitmq/amqp091-go v1.8.1
)

require (
github.com/golang/protobuf v1.5.3 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f // indirect
google.golang.org/grpc v1.54.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
)
32 changes: 32 additions & 0 deletions v3/integrations/nramqp/nramqp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package nramqp

import (
"context"

amqp "github.com/rabbitmq/amqp091-go"

"github.com/newrelic/go-agent/v3/newrelic"
)

type Channel struct {
amqpChan amqp.Channel
}

func (ch *Channel) ConsumeWithContext(ctx context.Context, queue, consumer string, autoAck, exclusive, noLocal, noWait bool, args amqp.Table) {
txn := newrelic.FromContext(ctx)
if txn != nil {

}
}

func (ch *Channel) PublishWithContext(ctx context.Context, exchange, key string, mandatory, immediate bool, msg amqp.Publishing) error {
txn := newrelic.FromContext(ctx)
if txn != nil {
txn.InsertDistributedTraceHeaders()

publishSegment := txn.StartSegment("MessageBroker/RabbitMQ/Channel/Publish")
defer publishSegment.End()
}

return ch.amqpChan.PublishWithContext(ctx, exchange, key, mandatory, immediate, msg)
}

0 comments on commit e3d6c12

Please sign in to comment.