func()

in plugins/amqp/producer.go [38:73]


func (p *ProducerInterceptor) BeforeInvoke(invocation operator.Invocation) error {
	channel := invocation.CallerInstance().(*nativeChannel)
	peer := getPeerInfo(channel.connection)
	exchange, routingKey, operationName := invocation.Args()[1].(string), invocation.Args()[2].(string), amqpSendPrefix
	if exchange != "" {
		exchange = invocation.Args()[1].(string)
		operationName += delimiter + exchange
	}
	if routingKey != "" {
		routingKey = invocation.Args()[2].(string)
		operationName += delimiter + routingKey
	}
	publishing := invocation.Args()[5].(amqp091.Publishing)
	operationName += amqpSendSuffix

	span, err := tracing.CreateExitSpan(operationName, peer, func(headerKey, headerValue string) error {
		if publishing.Headers == nil {
			publishing.Headers = amqp091.Table{
				headerKey: headerValue,
			}
			return nil
		}
		publishing.Headers[headerKey] = headerValue
		return nil
	}, tracing.WithLayer(tracing.SpanLayerMQ),
		tracing.WithComponent(ProducerComponentID),
		tracing.WithTag(tracing.TagMQBroker, peer),
		tracing.WithTag(tagMQExchange, exchange),
		tracing.WithTag(tagMQRoutingKey, routingKey),
	)
	if err != nil {
		return err
	}
	invocation.SetContext(span)
	return nil
}