@@ -37,10 +37,7 @@ use opentelemetry_sdk::{
37
37
} ,
38
38
Resource ,
39
39
} ;
40
- use opentelemetry_semantic_conventions:: resource:: SERVICE_NAME ;
41
- use opentelemetry_semantic_conventions:: trace:: {
42
- HTTP_METHOD , HTTP_ROUTE , HTTP_STATUS_CODE , HTTP_TARGET , HTTP_URL ,
43
- } ;
40
+ use opentelemetry_semantic_conventions as semconv;
44
41
use thiserror:: Error ;
45
42
#[ cfg( any( feature = "yup-authorizer" , feature = "gcp_auth" ) ) ]
46
43
use tonic:: metadata:: MetadataValue ;
@@ -54,8 +51,11 @@ use yup_oauth2::authenticator::Authenticator;
54
51
#[ allow( clippy:: derive_partial_eq_without_eq) ] // tonic doesn't derive Eq for generated types
55
52
pub mod proto;
56
53
57
- const HTTP_HOST : Key = Key :: from_static_str ( "http.host" ) ;
58
- const HTTP_USER_AGENT : Key = Key :: from_static_str ( "http.user_agent" ) ;
54
+ const HTTP_HOST : & str = "http.host" ;
55
+ const HTTP_PATH : & str = "http.path" ;
56
+ const HTTP_USER_AGENT : & str = "http.user_agent" ;
57
+
58
+ const GCP_HTTP_PATH : & str = "/http/path" ;
59
59
60
60
use proto:: devtools:: cloudtrace:: v2:: span:: time_event:: Annotation ;
61
61
use proto:: devtools:: cloudtrace:: v2:: span:: {
@@ -738,14 +738,14 @@ impl From<(Vec<KeyValue>, &Resource)> for Attributes {
738
738
return None ;
739
739
}
740
740
741
- if k == SERVICE_NAME {
741
+ if k. as_str ( ) == semconv :: resource :: SERVICE_NAME {
742
742
return Some ( ( GCP_SERVICE_NAME . to_owned ( ) , v. into ( ) ) ) ;
743
- } else if key == HTTP_PATH_ATTRIBUTE {
743
+ } else if key == HTTP_PATH {
744
744
return Some ( ( GCP_HTTP_PATH . to_owned ( ) , v. into ( ) ) ) ;
745
745
}
746
746
747
747
for ( otel_key, gcp_key) in KEY_MAP {
748
- if otel_key == & k {
748
+ if otel_key == k . as_str ( ) {
749
749
return Some ( ( gcp_key. to_owned ( ) , v. into ( ) ) ) ;
750
750
}
751
751
}
@@ -783,14 +783,15 @@ fn transform_links(links: &opentelemetry_sdk::trace::SpanLinks) -> Option<Links>
783
783
}
784
784
785
785
// Map conventional OpenTelemetry keys to their GCP counterparts.
786
- const KEY_MAP : [ ( & Key , & str ) ; 7 ] = [
787
- ( & HTTP_HOST , "/http/host" ) ,
788
- ( & HTTP_METHOD , "/http/method" ) ,
789
- ( & HTTP_TARGET , "/http/path" ) ,
790
- ( & HTTP_URL , "/http/url" ) ,
791
- ( & HTTP_USER_AGENT , "/http/user_agent" ) ,
792
- ( & HTTP_STATUS_CODE , "/http/status_code" ) ,
793
- ( & HTTP_ROUTE , "/http/route" ) ,
786
+ const KEY_MAP : [ ( & str , & str ) ; 8 ] = [
787
+ ( HTTP_HOST , "/http/host" ) ,
788
+ ( semconv:: trace:: HTTP_METHOD , "/http/method" ) ,
789
+ ( semconv:: trace:: HTTP_TARGET , "/http/path" ) ,
790
+ ( semconv:: trace:: HTTP_URL , "/http/url" ) ,
791
+ ( HTTP_USER_AGENT , "/http/user_agent" ) ,
792
+ ( semconv:: trace:: HTTP_STATUS_CODE , "/http/status_code" ) ,
793
+ ( semconv:: trace:: HTTP_ROUTE , "/http/route" ) ,
794
+ ( HTTP_PATH , GCP_HTTP_PATH ) ,
794
795
] ;
795
796
796
797
impl From < opentelemetry:: trace:: SpanKind > for SpanKind {
@@ -822,8 +823,6 @@ fn status(value: opentelemetry::trace::Status) -> Option<Status> {
822
823
}
823
824
const TRACE_APPEND : & str = "https://www.googleapis.com/auth/trace.append" ;
824
825
const LOGGING_WRITE : & str = "https://www.googleapis.com/auth/logging.write" ;
825
- const HTTP_PATH_ATTRIBUTE : & str = "http.path" ;
826
- const GCP_HTTP_PATH : & str = "/http/path" ;
827
826
const GCP_SERVICE_NAME : & str = "g.co/gae/app/module" ;
828
827
const MAX_ATTRIBUTES_PER_SPAN : usize = 32 ;
829
828
@@ -839,33 +838,40 @@ mod tests {
839
838
let mut attributes = Vec :: with_capacity ( capacity) ;
840
839
841
840
// hostAttribute = "http.host"
842
- attributes. push ( HTTP_HOST . string ( "example.com:8080" ) ) ;
841
+ attributes. push ( KeyValue :: new ( HTTP_HOST , "example.com:8080" ) ) ;
843
842
844
843
// methodAttribute = "http.method"
845
- attributes. push ( semcov:: trace:: HTTP_METHOD . string ( "POST" ) ) ;
844
+ attributes. push ( KeyValue :: new ( semcov:: trace:: HTTP_METHOD , "POST" ) ) ;
846
845
847
846
// pathAttribute = "http.path"
848
- attributes. push ( KeyValue :: new (
849
- "http.path" ,
850
- Value :: String ( "/path/12314/?q=ddds#123" . into ( ) ) ,
851
- ) ) ;
847
+ attributes. push ( KeyValue :: new ( HTTP_PATH , "/path/12314/?q=ddds#123" ) ) ;
852
848
853
849
// urlAttribute = "http.url"
854
- attributes. push (
855
- semcov:: trace:: HTTP_URL . string ( "https://example.com:8080/webshop/articles/4?s=1" ) ,
856
- ) ;
850
+ attributes. push ( KeyValue :: new (
851
+ semcov:: trace:: HTTP_URL ,
852
+ "https://example.com:8080/webshop/articles/4?s=1" ,
853
+ ) ) ;
857
854
858
855
// userAgentAttribute = "http.user_agent"
859
- attributes. push ( HTTP_USER_AGENT . string ( "CERN-LineMode/2.15 libwww/2.17b3" ) ) ;
856
+ attributes. push ( KeyValue :: new (
857
+ HTTP_USER_AGENT ,
858
+ "CERN-LineMode/2.15 libwww/2.17b3" ,
859
+ ) ) ;
860
860
861
861
// statusCodeAttribute = "http.status_code"
862
- attributes. push ( semcov:: trace:: HTTP_STATUS_CODE . i64 ( 200 ) ) ;
862
+ attributes. push ( KeyValue :: new ( semcov:: trace:: HTTP_STATUS_CODE , 200i64 ) ) ;
863
863
864
864
// statusCodeAttribute = "http.route"
865
- attributes. push ( semcov:: trace:: HTTP_ROUTE . string ( "/webshop/articles/:article_id" ) ) ;
865
+ attributes. push ( KeyValue :: new (
866
+ semcov:: trace:: HTTP_ROUTE ,
867
+ "/webshop/articles/:article_id" ,
868
+ ) ) ;
866
869
867
870
// serviceAttribute = "service.name"
868
- let resources = Resource :: new ( [ semcov:: resource:: SERVICE_NAME . string ( "Test Service Name" ) ] ) ;
871
+ let resources = Resource :: new ( [ KeyValue :: new (
872
+ semcov:: resource:: SERVICE_NAME ,
873
+ "Test Service Name" ,
874
+ ) ] ) ;
869
875
870
876
let actual: Attributes = ( attributes, & resources) . into ( ) ;
871
877
@@ -919,7 +925,10 @@ mod tests {
919
925
920
926
#[ test]
921
927
fn test_too_many ( ) {
922
- let resources = Resource :: new ( [ semcov:: resource:: SERVICE_NAME . string ( "Test Service Name" ) ] ) ;
928
+ let resources = Resource :: new ( [ KeyValue :: new (
929
+ semcov:: resource:: SERVICE_NAME ,
930
+ "Test Service Name" ,
931
+ ) ] ) ;
923
932
let mut attributes = Vec :: with_capacity ( 32 ) ;
924
933
for i in 0 ..32 {
925
934
attributes. push ( KeyValue :: new (
@@ -942,7 +951,10 @@ mod tests {
942
951
943
952
#[ test]
944
953
fn test_attributes_mapping_http_target ( ) {
945
- let attributes = vec ! [ semcov:: trace:: HTTP_TARGET . string( "/path/12314/?q=ddds#123" ) ] ;
954
+ let attributes = vec ! [ KeyValue :: new(
955
+ semcov:: trace:: HTTP_TARGET ,
956
+ "/path/12314/?q=ddds#123" ,
957
+ ) ] ;
946
958
947
959
// hostAttribute = "http.target"
948
960
0 commit comments