Skip to content

Commit

Permalink
feat(axiom): Update message segment to handle rabbitmq
Browse files Browse the repository at this point in the history
  • Loading branch information
zsistla committed Jan 25, 2025
1 parent 80be7a5 commit b50a5d2
Show file tree
Hide file tree
Showing 11 changed files with 423 additions and 9 deletions.
12 changes: 12 additions & 0 deletions axiom/nr_segment.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,15 @@ static void nr_populate_message_spans(nr_span_event_t* span_event,
segment->typed_attributes->message.messaging_system);
nr_span_event_set_message(span_event, NR_SPAN_MESSAGE_SERVER_ADDRESS,
segment->typed_attributes->message.server_address);
nr_span_event_set_message(
span_event, NR_SPAN_MESSAGE_MESSAGING_DESTINATION_ROUTING_KEY,
segment->typed_attributes->message.messaging_destination_routing_key);
nr_span_event_set_message(
span_event, NR_SPAN_MESSAGE_MESSAGING_DESTINATION_PUBLISH_NAME,
segment->typed_attributes->message.messaging_destination_publish_name);
nr_span_event_set_message_ulong(
span_event, NR_SPAN_MESSAGE_SERVER_PORT,
segment->typed_attributes->message.server_port);
}

static nr_status_t add_user_attribute_to_span_event(const char* key,
Expand Down Expand Up @@ -640,7 +649,10 @@ bool nr_segment_set_message(nr_segment_t* segment,
.message_action = message->message_action,
.destination_name = nr_strempty(message->destination_name) ? NULL: nr_strdup(message->destination_name),
.messaging_system = nr_strempty(message->messaging_system) ? NULL: nr_strdup(message->messaging_system),
.messaging_destination_routing_key = nr_strempty(message->messaging_destination_routing_key) ? NULL: nr_strdup(message->messaging_destination_routing_key),
.messaging_destination_publish_name = nr_strempty(message->messaging_destination_publish_name) ? NULL: nr_strdup(message->messaging_destination_publish_name),
.server_address = nr_strempty(message->server_address) ? NULL: nr_strdup(message->server_address),
.server_port = message->server_port,
};
// clang-format on

Expand Down
13 changes: 13 additions & 0 deletions axiom/nr_segment.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,19 @@ typedef struct _nr_segment_message_t {
char* messaging_system; /* for ex: aws_sqs. Needed for SQS relationship.*/
char* server_address; /*The server domain name or IP address. Needed for
MQBROKER relationship.*/
char*
messaging_destination_publish_name; /* Otel attribute for message
consumers. (In the agent, this
means Action is Consume in the span
name). This attribute is equal to
the corresponding attribute
messaging.destination.name from the
producer. This attribute is needed
for apps using RabbitMQ and it
represents the exchange name.*/
char* messaging_destination_routing_key; /* The routing key for a RabbitMQ
operation.*/
uint64_t server_port; /*The server port.*/
} nr_segment_message_t;

typedef struct _nr_segment_cloud_attrs_t {
Expand Down
5 changes: 5 additions & 0 deletions axiom/nr_segment_message.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ static void nr_segment_message_set_attrs(
message_attributes.destination_name = params->destination_name;
message_attributes.messaging_system = params->messaging_system;
message_attributes.server_address = params->server_address;
message_attributes.messaging_destination_routing_key
= params->messaging_destination_routing_key;
message_attributes.messaging_destination_publish_name
= params->messaging_destination_publish_name;
message_attributes.server_port = params->server_port;
}

nr_segment_set_message(segment, &message_attributes);
Expand Down
14 changes: 14 additions & 0 deletions axiom/nr_segment_message.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ typedef struct {
char* messaging_system; /* for ex: aws_sqs. Needed for SQS relationship.*/
char* server_address; /*The server domain name or IP address. Needed for
MQBROKER relationship.*/
char*
messaging_destination_publish_name; /* Otel attribute for message
consumers. (In the agent, this
means Action is Consume in the span
name). This attribute is equal to
the corresponding attribute
messaging.destination.name from the
producer. This attribute is needed
for apps using RabbitMQ and it
represents the exchange name.*/
char* messaging_destination_routing_key; /* The routing key for a RabbitMQ
operation.*/
uint64_t server_port; /*The server port.*/

} nr_segment_message_params_t;

/*
Expand Down
2 changes: 2 additions & 0 deletions axiom/nr_segment_private.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ void nr_segment_message_destroy_fields(nr_segment_message_t* message) {
nr_free(message->destination_name);
nr_free(message->messaging_system);
nr_free(message->server_address);
nr_free(message->messaging_destination_publish_name);
nr_free(message->messaging_destination_routing_key);
}

void nr_segment_destroy_typed_attributes(
Expand Down
10 changes: 10 additions & 0 deletions axiom/nr_segment_traces.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,16 @@ static void add_typed_attributes_to_buffer(nrbuf_t* buf,
message->messaging_system, false);
add_hash_key_value_to_buffer(buf, "server_address",
message->server_address, false);
add_hash_key_value_to_buffer(buf, "messaging_destination_publish_name",
message->messaging_destination_publish_name,
false);
add_hash_key_value_to_buffer(buf, "messaging_destination_routing_key",
message->messaging_destination_routing_key,
false);
if (0 != message->server_port) {
add_hash_key_value_to_buffer_int(buf, "server_port",
&message->server_port);
}
} break;
case NR_SEGMENT_CUSTOM:
default:
Expand Down
71 changes: 71 additions & 0 deletions axiom/nr_span_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,42 @@ void nr_span_event_set_message(nr_span_event_t* event,
nro_set_hash_string(event->agent_attributes, NR_ATTR_SERVER_ADDRESS,
new_value);
break;
case NR_SPAN_MESSAGE_MESSAGING_DESTINATION_ROUTING_KEY:
nro_set_hash_string(event->agent_attributes,
NR_ATTR_MESSAGING_DESTINATION_ROUTING_KEY, new_value);
break;
case NR_SPAN_MESSAGE_MESSAGING_DESTINATION_PUBLISH_NAME:
nro_set_hash_string(event->agent_attributes,
NR_ATTR_MESSAGING_DESTINATION_PUBLISH_NAME,
new_value);
break;
case NR_SPAN_MESSAGE_SERVER_PORT:
break;
}
}

void nr_span_event_set_message_ulong(nr_span_event_t* event,
nr_span_event_message_member_t member,
const uint64_t new_value) {
if (NULL == event || 0 == new_value) {
return;
}

switch (member) {
case NR_SPAN_MESSAGE_SERVER_PORT:
nro_set_hash_ulong(event->agent_attributes, NR_ATTR_SERVER_PORT,
new_value);
break;
case NR_SPAN_MESSAGE_DESTINATION_NAME:
break;
case NR_SPAN_MESSAGE_MESSAGING_SYSTEM:
break;
case NR_SPAN_MESSAGE_SERVER_ADDRESS:
break;
case NR_SPAN_MESSAGE_MESSAGING_DESTINATION_ROUTING_KEY:
break;
case NR_SPAN_MESSAGE_MESSAGING_DESTINATION_PUBLISH_NAME:
break;
}
}

Expand Down Expand Up @@ -535,10 +571,45 @@ const char* nr_span_event_get_message(const nr_span_event_t* event,
case NR_SPAN_MESSAGE_SERVER_ADDRESS:
return nro_get_hash_string(event->agent_attributes,
NR_ATTR_SERVER_ADDRESS, NULL);
case NR_SPAN_MESSAGE_MESSAGING_DESTINATION_ROUTING_KEY:
return nro_get_hash_string(event->agent_attributes,
NR_ATTR_MESSAGING_DESTINATION_ROUTING_KEY,
NULL);
case NR_SPAN_MESSAGE_MESSAGING_DESTINATION_PUBLISH_NAME:
return nro_get_hash_string(event->agent_attributes,
NR_ATTR_MESSAGING_DESTINATION_PUBLISH_NAME,
NULL);
case NR_SPAN_MESSAGE_SERVER_PORT:
break;
}
return NULL;
}

uint64_t nr_span_event_get_message_ulong(
const nr_span_event_t* event,
nr_span_event_message_member_t member) {
if (NULL == event) {
return 0;
}

switch (member) {
case NR_SPAN_MESSAGE_SERVER_PORT:
return nro_get_hash_ulong(event->agent_attributes, NR_ATTR_SERVER_PORT,
NULL);
case NR_SPAN_MESSAGE_DESTINATION_NAME:
break;
case NR_SPAN_MESSAGE_MESSAGING_SYSTEM:
break;
case NR_SPAN_MESSAGE_SERVER_ADDRESS:
break;
case NR_SPAN_MESSAGE_MESSAGING_DESTINATION_ROUTING_KEY:
break;
case NR_SPAN_MESSAGE_MESSAGING_DESTINATION_PUBLISH_NAME:
break;
}
return 0;
}

void nr_span_event_set_attribute_user(nr_span_event_t* event,
const char* name,
const nrobj_t* value) {
Expand Down
23 changes: 22 additions & 1 deletion axiom/nr_span_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@

#define NR_ATTR_MESSAGING_DESTINATION_NAME "messaging.destination.name"
#define NR_ATTR_MESSAGING_SYSTEM "messaging.system"
#define NR_ATTR_MESSAGING_DESTINATION_ROUTING_KEY \
"messaging.rabbitmq.destination.routing_key"
#define NR_ATTR_MESSAGING_DESTINATION_PUBLISH_NAME \
"messaging.destination_publish.name"
#define NR_ATTR_SERVER_ADDRESS "server.address"
#define NR_ATTR_SERVER_PORT "server.port"
#define NR_ATTR_CLOUD_REGION "cloud.region"
#define NR_ATTR_CLOUD_ACCOUNT_ID "cloud.account.id"
#define NR_ATTR_CLOUD_RESOURCE_ID "cloud.resource_id"
Expand Down Expand Up @@ -80,6 +85,9 @@ typedef enum {
NR_SPAN_MESSAGE_DESTINATION_NAME,
NR_SPAN_MESSAGE_MESSAGING_SYSTEM,
NR_SPAN_MESSAGE_SERVER_ADDRESS,
NR_SPAN_MESSAGE_SERVER_PORT,
NR_SPAN_MESSAGE_MESSAGING_DESTINATION_ROUTING_KEY,
NR_SPAN_MESSAGE_MESSAGING_DESTINATION_PUBLISH_NAME
} nr_span_event_message_member_t;

/*
Expand Down Expand Up @@ -211,7 +219,7 @@ extern void nr_span_event_set_external_status(nr_span_event_t* event,
const uint64_t status);

/*
* Purpose : Set a message attribute.
* Purpose : Set a message attribute with a given string new_value.
*
* Params : 1. The target Span Event that should be changed.
* 2. The message attribute to be set.
Expand All @@ -222,6 +230,19 @@ extern void nr_span_event_set_message(nr_span_event_t* event,
nr_span_event_message_member_t member,
const char* new_value);

/*
* Purpose : Set a message attribute with a given ulong new_value.
*
* Params : 1. The target Span Event that should be changed.
* 2. The message attribute to be set.
* 3. The ulong value that the field will be after the function has
* executed.
*/
extern void nr_span_event_set_message_ulong(
nr_span_event_t* event,
nr_span_event_message_member_t member,
const uint64_t new_value);

/*
* Purpose : Set a user attribute.
*
Expand Down
3 changes: 3 additions & 0 deletions axiom/nr_span_event_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ extern uint64_t nr_span_event_get_external_status(const nr_span_event_t* event);
extern const char* nr_span_event_get_message(
const nr_span_event_t* event,
nr_span_event_message_member_t member);
extern uint64_t nr_span_event_get_message_ulong(
const nr_span_event_t* event,
nr_span_event_message_member_t member);
extern const char* nr_span_event_get_error_message(
const nr_span_event_t* event);
extern const char* nr_span_event_get_error_class(const nr_span_event_t* event);
Expand Down
Loading

0 comments on commit b50a5d2

Please sign in to comment.