Skip to content

Commit

Permalink
Update to otel v0.19
Browse files Browse the repository at this point in the history
  • Loading branch information
markdingram committed Jun 8, 2023
1 parent cdce54e commit 73322e8
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 17 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Changed

* Update to otel v0.19

## [v0.13.0](https://github.com/OutThereLabs/actix-web-opentelemetry/compare/v0.13.0-alpha.1..v0.13.0)

### Changed
Expand Down
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ actix-http = { version = "3.0", default-features = false, features = ["compress-
actix-web = { version = "4.0", default-features = false, features = ["compress-zstd"] }
awc = { version = "3.0", optional = true, default-features = false, features = ["compress-zstd"] }
futures-util = { version = "0.3", default-features = false, features = ["alloc"] }
opentelemetry = { version = "0.18", default-features = false, features = ["trace", "rt-tokio-current-thread"] }
opentelemetry-prometheus = { version = "0.11", optional = true }
opentelemetry-semantic-conventions = "0.10"
opentelemetry = { version = "0.19", default-features = false, features = ["trace", "rt-tokio-current-thread"] }
opentelemetry-prometheus = { version = "0.12", optional = true }
opentelemetry-semantic-conventions = "0.11"
prometheus = { version = "0.13", default-features = false, optional = true }
serde = "1.0"

[dev-dependencies]
actix-web = { version = "4.0", features = ["macros"] }
actix-web-opentelemetry = { path = ".", features = ["metrics-prometheus", "sync-middleware", "awc"] }
opentelemetry-jaeger = { version = "0.17", features = ["rt-tokio-current-thread"] }
opentelemetry-jaeger = { version = "0.18", features = ["rt-tokio-current-thread"] }

[package.metadata.docs.rs]
all-features = true
Expand Down
1 change: 0 additions & 1 deletion examples/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ async fn main() -> io::Result<()> {
selectors::simple::histogram([1.0, 2.0, 5.0, 10.0, 20.0, 50.0]),
aggregation::cumulative_temporality_selector(),
)
.with_memory(true),
)
.build();

Expand Down
4 changes: 2 additions & 2 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use opentelemetry::{
};
use opentelemetry_semantic_conventions::trace::{
HTTP_FLAVOR, HTTP_METHOD, HTTP_REQUEST_CONTENT_LENGTH, HTTP_STATUS_CODE, HTTP_URL,
HTTP_USER_AGENT, NET_PEER_IP, NET_PEER_NAME, NET_PEER_PORT,
HTTP_USER_AGENT, NET_SOCK_PEER_ADDR, NET_PEER_NAME, NET_PEER_PORT,
};
use serde::Serialize;
use std::fmt::{self, Debug};
Expand Down Expand Up @@ -200,7 +200,7 @@ impl InstrumentedClientRequest {
}

if let Some(peer_addr) = self.request.get_peer_addr() {
self.attrs.push(NET_PEER_IP.string(peer_addr.to_string()));
self.attrs.push(NET_SOCK_PEER_ADDR.string(peer_addr.to_string()));
}

if let Some(peer_port) = self.request.get_uri().port_u16() {
Expand Down
20 changes: 10 additions & 10 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ use actix_web::{
#[cfg(feature = "metrics")]
use opentelemetry::KeyValue;
use opentelemetry::{trace::OrderMap, Key, Value};
use opentelemetry_semantic_conventions::trace::{
HTTP_CLIENT_IP, HTTP_FLAVOR, HTTP_HOST, HTTP_METHOD, HTTP_ROUTE, HTTP_SCHEME, HTTP_SERVER_NAME,
HTTP_TARGET, HTTP_USER_AGENT, NET_HOST_PORT, NET_PEER_IP,
};
use opentelemetry_semantic_conventions::{resource::HOST_NAME, trace::{
HTTP_CLIENT_IP, HTTP_FLAVOR, HTTP_METHOD, HTTP_ROUTE, HTTP_SCHEME,
HTTP_TARGET, HTTP_USER_AGENT, NET_HOST_NAME, NET_HOST_PORT, NET_SOCK_PEER_ADDR,
}};
#[cfg(feature = "awc")]
use std::fmt::Write;

Expand Down Expand Up @@ -88,13 +88,13 @@ pub(super) fn trace_attributes_from_request(
let mut attributes = OrderMap::with_capacity(11);
attributes.insert(HTTP_METHOD, http_method_str(req.method()));
attributes.insert(HTTP_FLAVOR, http_flavor(req.version()));
attributes.insert(HTTP_HOST, conn_info.host().to_string().into());
attributes.insert(HOST_NAME, conn_info.host().to_string().into());
attributes.insert(HTTP_ROUTE, http_route.to_owned().into());
attributes.insert(HTTP_SCHEME, http_scheme(conn_info.scheme()));

let server_name = req.app_config().host();
if server_name != conn_info.host() {
attributes.insert(HTTP_SERVER_NAME, server_name.to_string().into());
attributes.insert(NET_HOST_NAME, server_name.to_string().into());
}
if let Some(port) = conn_info
.host()
Expand Down Expand Up @@ -123,7 +123,7 @@ pub(super) fn trace_attributes_from_request(
if let Some(peer_addr) = req.peer_addr().map(|socket| socket.ip().to_string()) {
if Some(peer_addr.as_str()) != remote_addr {
// Client is going through a proxy
attributes.insert(NET_PEER_IP, peer_addr.into());
attributes.insert(NET_SOCK_PEER_ADDR, peer_addr.into());
}
}

Expand All @@ -140,13 +140,13 @@ pub(super) fn metrics_attributes_from_request(
let mut attributes = Vec::with_capacity(11);
attributes.push(KeyValue::new(HTTP_METHOD, http_method_str(req.method())));
attributes.push(KeyValue::new(HTTP_FLAVOR, http_flavor(req.version())));
attributes.push(HTTP_HOST.string(conn_info.host().to_string()));
attributes.push(HOST_NAME.string(conn_info.host().to_string()));
attributes.push(HTTP_TARGET.string(http_target.to_owned()));
attributes.push(KeyValue::new(HTTP_SCHEME, http_scheme(conn_info.scheme())));

let server_name = req.app_config().host();
if server_name != conn_info.host() {
attributes.push(HTTP_SERVER_NAME.string(server_name.to_string()));
attributes.push(NET_HOST_NAME.string(server_name.to_string()));
}
if let Some(port) = conn_info
.host()
Expand All @@ -161,7 +161,7 @@ pub(super) fn metrics_attributes_from_request(
if let Some(peer_addr) = req.peer_addr().map(|socket| socket.ip().to_string()) {
if Some(peer_addr.as_str()) != remote_addr {
// Client is going through a proxy
attributes.push(NET_PEER_IP.string(peer_addr))
attributes.push(NET_SOCK_PEER_ADDR.string(peer_addr))
}
}

Expand Down

0 comments on commit 73322e8

Please sign in to comment.