Skip to content

Commit f473bc9

Browse files
authored
move to using tracing instead of log (Azure#1579)
In order to move towards supporting OpenTelemetry, we need to move the underlying logging implementation to use `tracing`. This does _not_ start exposing spans or tracing state yet. ref: https://azure.github.io/azure-sdk/general_implementation.html
1 parent a3a681c commit f473bc9

File tree

76 files changed

+172
-181
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+172
-181
lines changed

sdk/core/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ bytes = "1.0"
2020
dyn-clone = "1.0"
2121
futures = "0.3"
2222
http-types = { version = "2.12", default-features = false }
23-
log = "0.4"
23+
tracing = "0.1.40"
2424
rand = "0.8"
2525
reqwest = { version = "0.11.14", features = [
2626
"stream",
@@ -48,7 +48,7 @@ getrandom = { version = "0.2", features = ["js"] }
4848
rustc_version = "0.4"
4949

5050
[dev-dependencies]
51-
env_logger = "0.10"
51+
tracing-subscriber = "0.3"
5252
tokio = { version = "1.0", features = ["default", "macros", "rt", "time"] }
5353
thiserror = "1.0"
5454

sdk/core/src/headers/utilities.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ pub fn delete_type_permanent_from_headers(headers: &Headers) -> crate::Result<bo
8080
if result.is_ok() {
8181
result
8282
} else {
83-
log::warn!("Error receiving delete type permanent. returning false");
83+
tracing::warn!("Error receiving delete type permanent. returning false");
8484
Ok(false)
8585
}
8686
}

sdk/core/src/http_client/reqwest.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ use crate::{
55
use async_trait::async_trait;
66
use futures::TryStreamExt;
77
use std::{collections::HashMap, str::FromStr, sync::Arc};
8+
use tracing::{debug, warn};
89

910
/// Construct a new `HttpClient` with the `reqwest` backend.
1011
pub fn new_reqwest_client() -> Arc<dyn HttpClient> {
11-
log::debug!("instantiating an http client using the reqwest backend");
12+
debug!("instantiating an http client using the reqwest backend");
1213

1314
// set `pool_max_idle_per_host` to `0` to avoid an issue in the underlying
1415
// `hyper` library that causes the `reqwest` client to hang in some cases.
@@ -53,7 +54,7 @@ impl HttpClient for ::reqwest::Client {
5354
}
5455
.context(ErrorKind::Other, "failed to build `reqwest` request")?;
5556

56-
log::debug!("performing request {method} '{url}' with `reqwest`");
57+
debug!("performing request {method} '{url}' with `reqwest`");
5758
let rsp = self
5859
.execute(reqwest_request)
5960
.await
@@ -89,7 +90,7 @@ fn to_headers(map: &::reqwest::header::HeaderMap) -> crate::headers::Headers {
8990
crate::headers::HeaderValue::from(value.to_owned()),
9091
))
9192
} else {
92-
log::warn!("header value for `{key}` is not utf8");
93+
warn!("header value for `{key}` is not utf8");
9394
None
9495
}
9596
})

sdk/core/src/parsing.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub fn from_azure_time(s: &str) -> crate::Result<time::OffsetDateTime> {
4949
if let Ok(dt) = date::parse_rfc1123(s) {
5050
Ok(dt)
5151
} else {
52-
log::warn!("Received an invalid date: {}, returning now()", s);
52+
tracing::warn!("Received an invalid date: {}, returning now()", s);
5353
Ok(time::OffsetDateTime::now_utc())
5454
}
5555
}

sdk/core/src/policies/custom_headers_policy.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
use crate::headers::Headers;
2-
use crate::policies::{Policy, PolicyResult};
3-
use crate::{Context, Request};
1+
use crate::{
2+
headers::Headers,
3+
policies::{Policy, PolicyResult},
4+
Context, Request,
5+
};
46
use std::sync::Arc;
7+
use tracing::trace;
58

69
#[derive(Debug, Clone)]
710
pub struct CustomHeaders(Headers);
@@ -28,7 +31,7 @@ impl Policy for CustomHeadersPolicy {
2831
custom_headers
2932
.iter()
3033
.for_each(|(header_name, header_value)| {
31-
log::trace!(
34+
trace!(
3235
"injecting custom context header {:?} with value {:?}",
3336
header_name,
3437
header_value

sdk/core/src/policies/retry_policies/retry_policy.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
use crate::date;
2-
use crate::error::{Error, ErrorKind, HttpError, ResultExt};
3-
use crate::headers::{Headers, RETRY_AFTER, RETRY_AFTER_MS, X_MS_RETRY_AFTER_MS};
4-
use crate::policies::{Policy, PolicyResult, Request};
5-
use crate::sleep::sleep;
6-
use crate::{Context, StatusCode};
7-
1+
use crate::{
2+
date,
3+
error::{Error, ErrorKind, HttpError, ResultExt},
4+
headers::{Headers, RETRY_AFTER, RETRY_AFTER_MS, X_MS_RETRY_AFTER_MS},
5+
policies::{Policy, PolicyResult, Request},
6+
sleep::sleep,
7+
Context, StatusCode,
8+
};
89
use async_trait::async_trait;
10+
use std::{sync::Arc, time::Duration};
911
use time::OffsetDateTime;
10-
11-
use std::sync::Arc;
12-
use std::time::Duration;
12+
use tracing::{debug, trace};
1313

1414
/// Attempts to parse the supplied string as an HTTP date, of the form defined by RFC 1123 (e.g. `Fri, 01 Jan 2021 00:00:00 GMT`).
1515
/// Returns `None` if the string is not a valid HTTP date.
@@ -122,7 +122,7 @@ where
122122
let start = start.get_or_insert_with(OffsetDateTime::now_utc);
123123
let (last_error, retry_after) = match result {
124124
Ok(response) if response.status().is_success() => {
125-
log::trace!(
125+
trace!(
126126
"Successful response. Request={:?} response={:?}",
127127
request,
128128
response
@@ -151,7 +151,7 @@ where
151151
);
152152

153153
if !RETRY_STATUSES.contains(&status) {
154-
log::debug!(
154+
debug!(
155155
"server returned error status which will not be retried: {}",
156156
status
157157
);
@@ -165,15 +165,15 @@ where
165165
);
166166
return Err(error);
167167
}
168-
log::debug!(
168+
debug!(
169169
"server returned error status which requires retry: {}",
170170
status
171171
);
172172
(Error::new(error_kind, http_error), retry_after)
173173
}
174174
Err(error) => {
175175
if error.kind() == &ErrorKind::Io {
176-
log::debug!(
176+
debug!(
177177
"io error occurred when making request which will be retried: {}",
178178
error
179179
);

sdk/core/src/policies/transport.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
use crate::policies::{Policy, PolicyResult};
2-
use crate::TransportOptions;
3-
use crate::{Context, Request};
1+
use crate::{
2+
policies::{Policy, PolicyResult},
3+
Context, Request, TransportOptions,
4+
};
45
use async_trait::async_trait;
56
use std::sync::Arc;
7+
use tracing::debug;
68

79
#[derive(Debug, Clone)]
810
pub struct TransportPolicy {
@@ -27,7 +29,7 @@ impl Policy for TransportPolicy {
2729
// there must be no more policies
2830
assert_eq!(0, next.len());
2931

30-
log::debug!("the following request will be passed to the transport policy: {request:#?}");
32+
debug!("the following request will be passed to the transport policy: {request:#?}");
3133
let response = { self.transport_options.send(ctx, request) };
3234

3335
response.await

sdk/core/src/tokio/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ use crate::{
44
setters,
55
};
66
use futures::{task::Poll, Future};
7-
use log::debug;
87
use std::{cmp::min, io::SeekFrom, pin::Pin, sync::Arc, task::Context};
98
use tokio::{
109
fs::File,
1110
io::{AsyncReadExt, AsyncSeekExt, Take},
1211
sync::Mutex,
1312
};
13+
use tracing::debug;
1414

1515
#[derive(Debug)]
1616
pub struct FileStreamBuilder {

sdk/data_cosmos/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ async-trait = "0.1"
1717
azure_core = { path = "../core", version = "0.19" }
1818
time = "0.3.10"
1919
futures = "0.3"
20-
log = "0.4"
20+
tracing = "0.1.40"
2121
serde = { version = "1.0", features = ["derive"] }
2222
serde_json = "1.0"
2323
url = "2.2"
@@ -26,7 +26,7 @@ thiserror = "1.0"
2626
bytes = "1.0"
2727

2828
[dev-dependencies]
29-
env_logger = "0.10"
29+
tracing-subscriber = "0.3"
3030
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
3131
clap = { version = "4.0.2", features = ["derive", "env"] }
3232
reqwest = "0.11.0"

sdk/data_cosmos/examples/cancellation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ struct Args {
1616

1717
#[tokio::main]
1818
async fn main() -> azure_core::Result<()> {
19-
env_logger::init();
19+
tracing_subscriber::fmt().init();
2020
// First we retrieve the account name and access key from environment variables, and
2121
// create an authorization token.
2222
let args = Args::parse();

sdk/data_cosmos/src/authorization_policy.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
use crate::resources::permission::AuthorizationToken;
2-
use crate::resources::ResourceType;
3-
use azure_core::headers::{HeaderValue, AUTHORIZATION, MS_DATE, VERSION};
4-
use azure_core::hmac::hmac_sha256;
5-
use azure_core::{date, Context, Policy, PolicyResult, Request, Url};
6-
use std::borrow::Cow;
7-
use std::sync::Arc;
1+
use crate::{resources::permission::AuthorizationToken, resources::ResourceType};
2+
use azure_core::{
3+
date,
4+
headers::{HeaderValue, AUTHORIZATION, MS_DATE, VERSION},
5+
hmac::hmac_sha256,
6+
Context, Policy, PolicyResult, Request, Url,
7+
};
8+
use std::{borrow::Cow, sync::Arc};
89
use time::OffsetDateTime;
10+
use tracing::trace;
911
use url::form_urlencoded;
1012

1113
const AZURE_VERSION: &str = "2018-12-31";

sdk/data_cosmos/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ async fn main() -> azure_core::Result<()> {
8787
#![deny(missing_docs)]
8888
#![recursion_limit = "256"]
8989
#[macro_use]
90-
extern crate log;
91-
#[macro_use]
9290
extern crate serde;
9391
#[macro_use]
9492
extern crate azure_core;

sdk/data_cosmos/src/operations/query_documents.rs

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use azure_core::{
1616
use serde::de::DeserializeOwned;
1717
use serde_json::Value;
1818
use time::OffsetDateTime;
19+
use tracing::warn;
1920

2021
operation! {
2122
#[stream]

sdk/data_cosmos/src/resource_quota.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use azure_core::error::{Error, ErrorKind};
2+
use tracing::{debug, trace};
23

34
/// A resource quota for the given resource kind
45
///

sdk/data_cosmos/src/resources/permission/authorization_token.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::PermissionToken;
22
use azure_core::auth::{Secret, TokenCredential};
3-
use std::fmt;
4-
use std::sync::Arc;
3+
use std::{fmt, sync::Arc};
4+
use tracing::trace;
55

66
/// Authorization tokens for accessing Cosmos.
77
///

sdk/data_cosmos/src/resources/permission/permission_token.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use super::AuthorizationToken;
22
use azure_core::{auth::Secret, base64};
3+
use tracing::trace;
34

45
const PERMISSION_TYPE_PREFIX: &str = "type=";
56
const VERSION_PREFIX: &str = "ver=";

sdk/data_cosmos/tests/collection_operations.rs

+14-13
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
11
use azure_data_cosmos::resources::collection::*;
22
use futures::StreamExt;
3+
use tracing::{debug, info};
34

45
mod setup_mock;
56

67
#[tokio::test]
78
async fn collection_operations() -> azure_core::Result<()> {
8-
env_logger::init();
9+
tracing_subscriber::fmt().init();
910

1011
let client = setup_mock::initialize("collection_operations")?;
1112
let database_name = "test-collection-operations";
1213

13-
log::info!("Creating a database with name '{}'...", database_name);
14+
info!("Creating a database with name '{}'...", database_name);
1415
client.create_database(database_name).await?;
15-
log::info!("Successfully created a database");
16+
info!("Successfully created a database");
1617

1718
// create collection!
1819
let database = client.database_client(database_name);
1920

2021
let collection_name = "sample_collection";
21-
log::info!("Creating a collection with name '{}'...", collection_name);
22+
info!("Creating a collection with name '{}'...", collection_name);
2223

2324
let create_collection_response = database.create_collection(collection_name, "/id").await?;
2425

2526
assert_eq!(create_collection_response.collection.id, collection_name);
2627

27-
log::info!("Successfully created a collection");
28-
log::debug!(
28+
info!("Successfully created a collection");
29+
debug!(
2930
"The create_collection response: {:#?}",
3031
create_collection_response
3132
);
@@ -37,8 +38,8 @@ async fn collection_operations() -> azure_core::Result<()> {
3738

3839
assert_eq!(get_collection.collection.id, collection_name);
3940

40-
log::info!("Successfully got a collection");
41-
log::debug!("The get_collection response: {:#?}", get_collection);
41+
info!("Successfully got a collection");
42+
debug!("The get_collection response: {:#?}", get_collection);
4243

4344
let collections = database
4445
.list_collections()
@@ -99,24 +100,24 @@ async fn collection_operations() -> azure_core::Result<()> {
99100
"/\"excludeme\"/?"
100101
);
101102

102-
log::info!("Successfully replaced collection");
103-
log::debug!(
103+
info!("Successfully replaced collection");
104+
debug!(
104105
"The replace_collection response: {:#?}",
105106
replace_collection_response
106107
);
107108

108109
// delete collection!
109110
let delete_collection_response = collection.delete_collection().await?;
110111

111-
log::info!("Successfully deleted collection");
112-
log::debug!(
112+
info!("Successfully deleted collection");
113+
debug!(
113114
"The delete_collection response: {:#?}",
114115
delete_collection_response
115116
);
116117

117118
// delete database
118119
database.delete_database().await?;
119-
log::info!("Successfully deleted database");
120+
info!("Successfully deleted database");
120121

121122
Ok(())
122123
}

0 commit comments

Comments
 (0)