@@ -220,6 +220,7 @@ impl Builder {
220
220
221
221
let count_clone = pending_count. clone ( ) ;
222
222
let resource = Arc :: new ( RwLock :: new ( None ) ) ;
223
+ let ctx_resource = resource. clone ( ) ;
223
224
let future = async move {
224
225
let trace_client = TraceServiceClient :: new ( trace_channel) ;
225
226
let authorizer = & authenticator;
@@ -229,7 +230,7 @@ impl Builder {
229
230
let log_client = log_client. clone ( ) ;
230
231
let pending_count = count_clone. clone ( ) ;
231
232
let scopes = scopes. clone ( ) ;
232
- let resource = resource . clone ( ) ;
233
+ let resource = ctx_resource . clone ( ) ;
233
234
ExporterContext {
234
235
trace_client,
235
236
log_client,
@@ -248,7 +249,7 @@ impl Builder {
248
249
pending_count,
249
250
maximum_shutdown_duration : maximum_shutdown_duration
250
251
. unwrap_or_else ( || Duration :: from_secs ( 5 ) ) ,
251
- resource : Arc :: new ( RwLock :: new ( None ) ) ,
252
+ resource,
252
253
} ;
253
254
254
255
Ok ( ( exporter, future) )
@@ -772,8 +773,7 @@ fn transform_links(links: &opentelemetry_sdk::trace::SpanLinks) -> Option<Links>
772
773
// Map conventional OpenTelemetry keys to their GCP counterparts.
773
774
//
774
775
// https://cloud.google.com/trace/docs/trace-labels
775
- const KEY_MAP : [ ( & str , & str ) ; 16 ] = [
776
- ( semconv:: resource:: SERVICE_NAME , GCP_SERVICE_NAME ) ,
776
+ const KEY_MAP : [ ( & str , & str ) ; 19 ] = [
777
777
( HTTP_PATH , GCP_HTTP_PATH ) ,
778
778
( semconv:: attribute:: HTTP_HOST , "/http/host" ) ,
779
779
( "http.request.header.host" , "/http/host" ) ,
@@ -786,10 +786,27 @@ const KEY_MAP: [(&str, &str); 16] = [
786
786
( semconv:: attribute:: HTTP_USER_AGENT , "/http/user_agent" ) ,
787
787
( semconv:: attribute:: USER_AGENT_ORIGINAL , "/http/user_agent" ) ,
788
788
( semconv:: attribute:: HTTP_STATUS_CODE , "/http/status_code" ) ,
789
+ // https://cloud.google.com/trace/docs/trace-labels#canonical-gke
789
790
(
790
791
semconv:: attribute:: HTTP_RESPONSE_STATUS_CODE ,
791
792
"/http/status_code" ,
792
793
) ,
794
+ (
795
+ semconv:: attribute:: K8S_CLUSTER_NAME ,
796
+ "g.co/r/k8s_container/cluster_name" ,
797
+ ) ,
798
+ (
799
+ semconv:: attribute:: K8S_NAMESPACE_NAME ,
800
+ "g.co/r/k8s_container/namespace" ,
801
+ ) ,
802
+ (
803
+ semconv:: attribute:: K8S_POD_NAME ,
804
+ "g.co/r/k8s_container/pod_name" ,
805
+ ) ,
806
+ (
807
+ semconv:: attribute:: K8S_CONTAINER_NAME ,
808
+ "g.co/r/k8s_container/container_name" ,
809
+ ) ,
793
810
( semconv:: trace:: HTTP_ROUTE , "/http/route" ) ,
794
811
( HTTP_PATH , GCP_HTTP_PATH ) ,
795
812
] ;
@@ -826,7 +843,6 @@ fn status(value: opentelemetry::trace::Status) -> Option<Status> {
826
843
}
827
844
const TRACE_APPEND : & str = "https://www.googleapis.com/auth/trace.append" ;
828
845
const LOGGING_WRITE : & str = "https://www.googleapis.com/auth/logging.write" ;
829
- const GCP_SERVICE_NAME : & str = "g.co/gae/app/module" ;
830
846
const MAX_ATTRIBUTES_PER_SPAN : usize = 32 ;
831
847
832
848
#[ cfg( test) ]
@@ -920,19 +936,13 @@ mod tests {
920
936
actual. attribute_map. get( "/http/status_code" ) ,
921
937
Some ( & AttributeValue :: from( Value :: I64 ( 200 ) ) ) ,
922
938
) ;
923
- assert_eq ! (
924
- actual. attribute_map. get( "g.co/gae/app/module" ) ,
925
- Some ( & AttributeValue :: from( Value :: String (
926
- "Test Service Name" . into( )
927
- ) ) ) ,
928
- ) ;
929
939
}
930
940
931
941
#[ test]
932
942
fn test_too_many ( ) {
933
943
let resources = Resource :: new ( [ KeyValue :: new (
934
- semcov :: resource :: SERVICE_NAME ,
935
- "Test Service Name" ,
944
+ semconv :: attribute :: USER_AGENT_ORIGINAL ,
945
+ "Test Service Name UA " ,
936
946
) ] ) ;
937
947
let mut attributes = Vec :: with_capacity ( 32 ) ;
938
948
for i in 0 ..32 {
@@ -946,9 +956,9 @@ mod tests {
946
956
assert_eq ! ( actual. attribute_map. len( ) , 32 ) ;
947
957
assert_eq ! ( actual. dropped_attributes_count, 1 ) ;
948
958
assert_eq ! (
949
- actual. attribute_map. get( "g.co/gae/app/module " ) ,
959
+ actual. attribute_map. get( "/http/user_agent " ) ,
950
960
Some ( & AttributeValue :: from( Value :: String (
951
- "Test Service Name" . into( )
961
+ "Test Service Name UA " . into( )
952
962
) ) ) ,
953
963
) ;
954
964
}
0 commit comments