@ -25,6 +25,7 @@
# include "opentelemetry/sdk/metrics/meter_provider.h"
# include "opentelemetry/sdk/metrics/meter_provider.h"
# include "opentelemetry/sdk/metrics/metric_reader.h"
# include "opentelemetry/sdk/metrics/metric_reader.h"
# include <grpcpp/ext/otel_plugin.h>
# include <grpcpp/grpcpp.h>
# include <grpcpp/grpcpp.h>
# include "src/core/lib/channel/call_tracer.h"
# include "src/core/lib/channel/call_tracer.h"
@ -37,16 +38,21 @@ namespace grpc {
namespace testing {
namespace testing {
namespace {
namespace {
TEST ( OTelPluginBuildTest , ApiDependency ) {
TEST ( Open Telemetry PluginBuildTest , ApiDependency ) {
opentelemetry : : metrics : : Provider : : GetMeterProvider ( ) ;
opentelemetry : : metrics : : Provider : : GetMeterProvider ( ) ;
}
}
TEST ( OTelPluginBuildTest , SdkDependency ) {
TEST ( Open Telemetry PluginBuildTest , SdkDependency ) {
opentelemetry : : sdk : : metrics : : MeterProvider ( ) ;
opentelemetry : : sdk : : metrics : : MeterProvider ( ) ;
}
}
TEST_F ( OTelPluginEnd2EndTest , ClientAttemptStarted ) {
TEST ( OpenTelemetryPluginBuildTest , Basic ) {
Init ( { grpc : : internal : : OTelClientAttemptStartedInstrumentName ( ) } ) ;
grpc : : experimental : : OpenTelemetryPluginBuilder builder ;
}
TEST_F ( OpenTelemetryPluginEnd2EndTest , ClientAttemptStarted ) {
Init ( { grpc : : experimental : : OpenTelemetryPluginBuilder : :
kClientAttemptStartedInstrumentName } ) ;
SendRPC ( ) ;
SendRPC ( ) ;
const char * kMetricName = " grpc.client.attempt.started " ;
const char * kMetricName = " grpc.client.attempt.started " ;
auto data = ReadCurrentMetricsData (
auto data = ReadCurrentMetricsData (
@ -73,8 +79,9 @@ TEST_F(OTelPluginEnd2EndTest, ClientAttemptStarted) {
EXPECT_EQ ( * target_value , canonical_server_address_ ) ;
EXPECT_EQ ( * target_value , canonical_server_address_ ) ;
}
}
TEST_F ( OTelPluginEnd2EndTest , ClientAttemptDuration ) {
TEST_F ( OpenTelemetryPluginEnd2EndTest , ClientAttemptDuration ) {
Init ( { grpc : : internal : : OTelClientAttemptDurationInstrumentName ( ) } ) ;
Init ( { grpc : : experimental : : OpenTelemetryPluginBuilder : :
kClientAttemptDurationInstrumentName } ) ;
SendRPC ( ) ;
SendRPC ( ) ;
const char * kMetricName = " grpc.client.attempt.duration " ;
const char * kMetricName = " grpc.client.attempt.duration " ;
auto data = ReadCurrentMetricsData (
auto data = ReadCurrentMetricsData (
@ -104,9 +111,10 @@ TEST_F(OTelPluginEnd2EndTest, ClientAttemptDuration) {
EXPECT_EQ ( * status_value , " OK " ) ;
EXPECT_EQ ( * status_value , " OK " ) ;
}
}
TEST_F ( OTelPluginEnd2EndTest , ClientAttemptSentTotalCompressedMessageSize ) {
TEST_F ( OpenTelemetryPluginEnd2EndTest ,
Init ( { grpc : : internal : :
ClientAttemptSentTotalCompressedMessageSize ) {
OTelClientAttemptSentTotalCompressedMessageSizeInstrumentName ( ) } ) ;
Init ( { grpc : : experimental : : OpenTelemetryPluginBuilder : :
kClientAttemptSentTotalCompressedMessageSizeInstrumentName } ) ;
SendRPC ( ) ;
SendRPC ( ) ;
const char * kMetricName =
const char * kMetricName =
" grpc.client.attempt.sent_total_compressed_message_size " ;
" grpc.client.attempt.sent_total_compressed_message_size " ;
@ -138,9 +146,10 @@ TEST_F(OTelPluginEnd2EndTest, ClientAttemptSentTotalCompressedMessageSize) {
EXPECT_EQ ( * status_value , " OK " ) ;
EXPECT_EQ ( * status_value , " OK " ) ;
}
}
TEST_F ( OTelPluginEnd2EndTest , ClientAttemptRcvdTotalCompressedMessageSize ) {
TEST_F ( OpenTelemetryPluginEnd2EndTest ,
Init ( { grpc : : internal : :
ClientAttemptRcvdTotalCompressedMessageSize ) {
OTelClientAttemptRcvdTotalCompressedMessageSizeInstrumentName ( ) } ) ;
Init ( { grpc : : experimental : : OpenTelemetryPluginBuilder : :
kClientAttemptRcvdTotalCompressedMessageSizeInstrumentName } ) ;
SendRPC ( ) ;
SendRPC ( ) ;
const char * kMetricName =
const char * kMetricName =
" grpc.client.attempt.rcvd_total_compressed_message_size " ;
" grpc.client.attempt.rcvd_total_compressed_message_size " ;
@ -172,8 +181,9 @@ TEST_F(OTelPluginEnd2EndTest, ClientAttemptRcvdTotalCompressedMessageSize) {
EXPECT_EQ ( * status_value , " OK " ) ;
EXPECT_EQ ( * status_value , " OK " ) ;
}
}
TEST_F ( OTelPluginEnd2EndTest , ServerCallStarted ) {
TEST_F ( OpenTelemetryPluginEnd2EndTest , ServerCallStarted ) {
Init ( { grpc : : internal : : OTelServerCallStartedInstrumentName ( ) } ) ;
Init ( { grpc : : experimental : : OpenTelemetryPluginBuilder : :
kServerCallStartedInstrumentName } ) ;
SendRPC ( ) ;
SendRPC ( ) ;
const char * kMetricName = " grpc.server.call.started " ;
const char * kMetricName = " grpc.server.call.started " ;
auto data = ReadCurrentMetricsData (
auto data = ReadCurrentMetricsData (
@ -196,8 +206,9 @@ TEST_F(OTelPluginEnd2EndTest, ServerCallStarted) {
EXPECT_EQ ( * method_value , kMethodName ) ;
EXPECT_EQ ( * method_value , kMethodName ) ;
}
}
TEST_F ( OTelPluginEnd2EndTest , ServerCallDuration ) {
TEST_F ( OpenTelemetryPluginEnd2EndTest , ServerCallDuration ) {
Init ( { grpc : : internal : : OTelServerCallDurationInstrumentName ( ) } ) ;
Init ( { grpc : : experimental : : OpenTelemetryPluginBuilder : :
kServerCallDurationInstrumentName } ) ;
SendRPC ( ) ;
SendRPC ( ) ;
const char * kMetricName = " grpc.server.call.duration " ;
const char * kMetricName = " grpc.server.call.duration " ;
auto data = ReadCurrentMetricsData (
auto data = ReadCurrentMetricsData (
@ -223,9 +234,10 @@ TEST_F(OTelPluginEnd2EndTest, ServerCallDuration) {
EXPECT_EQ ( * status_value , " OK " ) ;
EXPECT_EQ ( * status_value , " OK " ) ;
}
}
TEST_F ( OTelPluginEnd2EndTest , ServerCallSentTotalCompressedMessageSize ) {
TEST_F ( OpenTelemetryPluginEnd2EndTest ,
Init ( { grpc : : internal : :
ServerCallSentTotalCompressedMessageSize ) {
OTelServerCallSentTotalCompressedMessageSizeInstrumentName ( ) } ) ;
Init ( { grpc : : experimental : : OpenTelemetryPluginBuilder : :
kServerCallSentTotalCompressedMessageSizeInstrumentName } ) ;
SendRPC ( ) ;
SendRPC ( ) ;
const char * kMetricName =
const char * kMetricName =
" grpc.server.call.sent_total_compressed_message_size " ;
" grpc.server.call.sent_total_compressed_message_size " ;
@ -253,9 +265,10 @@ TEST_F(OTelPluginEnd2EndTest, ServerCallSentTotalCompressedMessageSize) {
EXPECT_EQ ( * status_value , " OK " ) ;
EXPECT_EQ ( * status_value , " OK " ) ;
}
}
TEST_F ( OTelPluginEnd2EndTest , ServerCallRcvdTotalCompressedMessageSize ) {
TEST_F ( OpenTelemetryPluginEnd2EndTest ,
Init ( { grpc : : internal : :
ServerCallRcvdTotalCompressedMessageSize ) {
OTelServerCallRcvdTotalCompressedMessageSizeInstrumentName ( ) } ) ;
Init ( { grpc : : experimental : : OpenTelemetryPluginBuilder : :
kServerCallRcvdTotalCompressedMessageSizeInstrumentName } ) ;
SendRPC ( ) ;
SendRPC ( ) ;
const char * kMetricName =
const char * kMetricName =
" grpc.server.call.rcvd_total_compressed_message_size " ;
" grpc.server.call.rcvd_total_compressed_message_size " ;
@ -284,8 +297,9 @@ TEST_F(OTelPluginEnd2EndTest, ServerCallRcvdTotalCompressedMessageSize) {
}
}
// Make sure that no meter provider results in normal operations.
// Make sure that no meter provider results in normal operations.
TEST_F ( OTelPluginEnd2EndTest , NoMeterProviderRegistered ) {
TEST_F ( OpenTelemetryPluginEnd2EndTest , NoMeterProviderRegistered ) {
Init ( { grpc : : internal : : OTelClientAttemptStartedInstrumentName ( ) } ,
Init ( { grpc : : experimental : : OpenTelemetryPluginBuilder : :
kClientAttemptStartedInstrumentName } ,
/*resource=*/ opentelemetry : : sdk : : resource : : Resource : : Create ( { } ) ,
/*resource=*/ opentelemetry : : sdk : : resource : : Resource : : Create ( { } ) ,
/*labels_injector=*/ nullptr ,
/*labels_injector=*/ nullptr ,
/*test_no_meter_provider=*/ true ) ;
/*test_no_meter_provider=*/ true ) ;
@ -293,8 +307,9 @@ TEST_F(OTelPluginEnd2EndTest, NoMeterProviderRegistered) {
}
}
// Test that a channel selector returning true records metrics on the channel.
// Test that a channel selector returning true records metrics on the channel.
TEST_F ( OTelPluginEnd2EndTest , TargetSelectorReturnsTrue ) {
TEST_F ( OpenTelemetryPluginEnd2EndTest , TargetSelectorReturnsTrue ) {
Init ( { grpc : : internal : : OTelClientAttemptStartedInstrumentName ( ) } , /*resource=*/
Init ( { grpc : : experimental : : OpenTelemetryPluginBuilder : :
kClientAttemptStartedInstrumentName } , /*resource=*/
opentelemetry : : sdk : : resource : : Resource : : Create ( { } ) ,
opentelemetry : : sdk : : resource : : Resource : : Create ( { } ) ,
/*labels_injector=*/ nullptr ,
/*labels_injector=*/ nullptr ,
/*test_no_meter_provider=*/ false ,
/*test_no_meter_provider=*/ false ,
@ -328,8 +343,9 @@ TEST_F(OTelPluginEnd2EndTest, TargetSelectorReturnsTrue) {
// Test that a target selector returning false does not record metrics on the
// Test that a target selector returning false does not record metrics on the
// channel.
// channel.
TEST_F ( OTelPluginEnd2EndTest , TargetSelectorReturnsFalse ) {
TEST_F ( OpenTelemetryPluginEnd2EndTest , TargetSelectorReturnsFalse ) {
Init ( { grpc : : internal : : OTelClientAttemptStartedInstrumentName ( ) } , /*resource=*/
Init ( { grpc : : experimental : : OpenTelemetryPluginBuilder : :
kClientAttemptStartedInstrumentName } , /*resource=*/
opentelemetry : : sdk : : resource : : Resource : : Create ( { } ) ,
opentelemetry : : sdk : : resource : : Resource : : Create ( { } ) ,
/*labels_injector=*/ nullptr ,
/*labels_injector=*/ nullptr ,
/*test_no_meter_provider=*/ false ,
/*test_no_meter_provider=*/ false ,
@ -346,8 +362,9 @@ TEST_F(OTelPluginEnd2EndTest, TargetSelectorReturnsFalse) {
// Test that a target attribute filter returning true records metrics with the
// Test that a target attribute filter returning true records metrics with the
// target as is on the channel.
// target as is on the channel.
TEST_F ( OTelPluginEnd2EndTest , TargetAttributeFilterReturnsTrue ) {
TEST_F ( OpenTelemetryPluginEnd2EndTest , TargetAttributeFilterReturnsTrue ) {
Init ( { grpc : : internal : : OTelClientAttemptStartedInstrumentName ( ) } , /*resource=*/
Init ( { grpc : : experimental : : OpenTelemetryPluginBuilder : :
kClientAttemptStartedInstrumentName } , /*resource=*/
opentelemetry : : sdk : : resource : : Resource : : Create ( { } ) ,
opentelemetry : : sdk : : resource : : Resource : : Create ( { } ) ,
/*labels_injector=*/ nullptr ,
/*labels_injector=*/ nullptr ,
/*test_no_meter_provider=*/ false ,
/*test_no_meter_provider=*/ false ,
@ -383,8 +400,9 @@ TEST_F(OTelPluginEnd2EndTest, TargetAttributeFilterReturnsTrue) {
// Test that a target attribute filter returning false records metrics with the
// Test that a target attribute filter returning false records metrics with the
// target as "other".
// target as "other".
TEST_F ( OTelPluginEnd2EndTest , TargetAttributeFilterReturnsFalse ) {
TEST_F ( OpenTelemetryPluginEnd2EndTest , TargetAttributeFilterReturnsFalse ) {
Init ( { grpc : : internal : : OTelClientAttemptStartedInstrumentName ( ) } , /*resource=*/
Init ( { grpc : : experimental : : OpenTelemetryPluginBuilder : :
kClientAttemptStartedInstrumentName } , /*resource=*/
opentelemetry : : sdk : : resource : : Resource : : Create ( { } ) ,
opentelemetry : : sdk : : resource : : Resource : : Create ( { } ) ,
/*labels_injector=*/ nullptr ,
/*labels_injector=*/ nullptr ,
/*test_no_meter_provider=*/ false ,
/*test_no_meter_provider=*/ false ,
@ -419,8 +437,9 @@ TEST_F(OTelPluginEnd2EndTest, TargetAttributeFilterReturnsFalse) {
}
}
// Test that generic method names are scrubbed properly on the client side.
// Test that generic method names are scrubbed properly on the client side.
TEST_F ( OTelPluginEnd2EndTest , GenericClientRpc ) {
TEST_F ( OpenTelemetryPluginEnd2EndTest , GenericClientRpc ) {
Init ( { grpc : : internal : : OTelClientAttemptStartedInstrumentName ( ) } ) ;
Init ( { grpc : : experimental : : OpenTelemetryPluginBuilder : :
kClientAttemptStartedInstrumentName } ) ;
SendGenericRPC ( ) ;
SendGenericRPC ( ) ;
const char * kMetricName = " grpc.client.attempt.started " ;
const char * kMetricName = " grpc.client.attempt.started " ;
auto data = ReadCurrentMetricsData (
auto data = ReadCurrentMetricsData (
@ -449,9 +468,10 @@ TEST_F(OTelPluginEnd2EndTest, GenericClientRpc) {
// Test that generic method names are scrubbed properly on the client side if
// Test that generic method names are scrubbed properly on the client side if
// the method attribute filter is set and it returns false.
// the method attribute filter is set and it returns false.
TEST_F ( OTelPluginEnd2EndTest ,
TEST_F ( Open Telemetry PluginEnd2EndTest ,
GenericClientRpcWithMethodAttributeFilterReturningFalse ) {
GenericClientRpcWithMethodAttributeFilterReturningFalse ) {
Init ( { grpc : : internal : : OTelClientAttemptStartedInstrumentName ( ) } ,
Init ( { grpc : : experimental : : OpenTelemetryPluginBuilder : :
kClientAttemptStartedInstrumentName } ,
/*resource=*/ opentelemetry : : sdk : : resource : : Resource : : Create ( { } ) ,
/*resource=*/ opentelemetry : : sdk : : resource : : Resource : : Create ( { } ) ,
/*labels_injector=*/ nullptr ,
/*labels_injector=*/ nullptr ,
/*test_no_meter_provider=*/ false ,
/*test_no_meter_provider=*/ false ,
@ -488,9 +508,10 @@ TEST_F(OTelPluginEnd2EndTest,
// Test that generic method names is not scrubbed on the client side if
// Test that generic method names is not scrubbed on the client side if
// the method attribute filter is set and it returns true.
// the method attribute filter is set and it returns true.
TEST_F ( OTelPluginEnd2EndTest ,
TEST_F ( Open Telemetry PluginEnd2EndTest ,
GenericClientRpcWithMethodAttributeFilterReturningTrue ) {
GenericClientRpcWithMethodAttributeFilterReturningTrue ) {
Init ( { grpc : : internal : : OTelClientAttemptStartedInstrumentName ( ) } ,
Init ( { grpc : : experimental : : OpenTelemetryPluginBuilder : :
kClientAttemptStartedInstrumentName } ,
/*resource=*/ opentelemetry : : sdk : : resource : : Resource : : Create ( { } ) ,
/*resource=*/ opentelemetry : : sdk : : resource : : Resource : : Create ( { } ) ,
/*labels_injector=*/ nullptr ,
/*labels_injector=*/ nullptr ,
/*test_no_meter_provider=*/ false ,
/*test_no_meter_provider=*/ false ,
@ -526,8 +547,9 @@ TEST_F(OTelPluginEnd2EndTest,
}
}
// Test that generic method names are scrubbed properly on the server side.
// Test that generic method names are scrubbed properly on the server side.
TEST_F ( OTelPluginEnd2EndTest , GenericServerRpc ) {
TEST_F ( OpenTelemetryPluginEnd2EndTest , GenericServerRpc ) {
Init ( { grpc : : internal : : OTelServerCallDurationInstrumentName ( ) } ) ;
Init ( { grpc : : experimental : : OpenTelemetryPluginBuilder : :
kServerCallDurationInstrumentName } ) ;
SendGenericRPC ( ) ;
SendGenericRPC ( ) ;
const char * kMetricName = " grpc.server.call.duration " ;
const char * kMetricName = " grpc.server.call.duration " ;
auto data = ReadCurrentMetricsData (
auto data = ReadCurrentMetricsData (
@ -555,9 +577,10 @@ TEST_F(OTelPluginEnd2EndTest, GenericServerRpc) {
// Test that generic method names are scrubbed properly on the server side if
// Test that generic method names are scrubbed properly on the server side if
// the method attribute filter is set and it returns false.
// the method attribute filter is set and it returns false.
TEST_F ( OTelPluginEnd2EndTest ,
TEST_F ( Open Telemetry PluginEnd2EndTest ,
GenericServerRpcWithMethodAttributeFilterReturningFalse ) {
GenericServerRpcWithMethodAttributeFilterReturningFalse ) {
Init ( { grpc : : internal : : OTelServerCallDurationInstrumentName ( ) } ,
Init ( { grpc : : experimental : : OpenTelemetryPluginBuilder : :
kServerCallDurationInstrumentName } ,
/*resource=*/ opentelemetry : : sdk : : resource : : Resource : : Create ( { } ) ,
/*resource=*/ opentelemetry : : sdk : : resource : : Resource : : Create ( { } ) ,
/*labels_injector=*/ nullptr ,
/*labels_injector=*/ nullptr ,
/*test_no_meter_provider=*/ false ,
/*test_no_meter_provider=*/ false ,
@ -593,9 +616,10 @@ TEST_F(OTelPluginEnd2EndTest,
// Test that generic method names are not scrubbed on the server side if
// Test that generic method names are not scrubbed on the server side if
// the method attribute filter is set and it returns true.
// the method attribute filter is set and it returns true.
TEST_F ( OTelPluginEnd2EndTest ,
TEST_F ( Open Telemetry PluginEnd2EndTest ,
GenericServerRpcWithMethodAttributeFilterReturningTrue ) {
GenericServerRpcWithMethodAttributeFilterReturningTrue ) {
Init ( { grpc : : internal : : OTelServerCallDurationInstrumentName ( ) } ,
Init ( { grpc : : experimental : : OpenTelemetryPluginBuilder : :
kServerCallDurationInstrumentName } ,
/*resource=*/ opentelemetry : : sdk : : resource : : Resource : : Create ( { } ) ,
/*resource=*/ opentelemetry : : sdk : : resource : : Resource : : Create ( { } ) ,
/*labels_injector=*/ nullptr ,
/*labels_injector=*/ nullptr ,
/*test_no_meter_provider=*/ false ,
/*test_no_meter_provider=*/ false ,