Skip to content

Commit 71bb86a

Browse files
committed
Add test to confirm known bug
1 parent 832fad4 commit 71bb86a

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

opentelemetry-sdk/src/metrics/meter.rs

+20-5
Original file line numberDiff line numberDiff line change
@@ -762,14 +762,26 @@ where
762762
mod tests {
763763
use std::sync::Arc;
764764

765-
use opentelemetry::metrics::{InstrumentProvider, MetricsError, Unit};
765+
use opentelemetry::metrics::{InstrumentProvider, MeterProvider, MetricsError, Unit};
766766

767767
use super::{
768768
InstrumentValidationPolicy, SdkMeter, INSTRUMENT_NAME_FIRST_ALPHABETIC,
769769
INSTRUMENT_NAME_INVALID_CHAR, INSTRUMENT_NAME_LENGTH, INSTRUMENT_UNIT_INVALID_CHAR,
770770
INSTRUMENT_UNIT_LENGTH,
771771
};
772-
use crate::{metrics::pipeline::Pipelines, Resource, Scope};
772+
use crate::{metrics::{pipeline::Pipelines, SdkMeterProvider}, Resource, Scope};
773+
774+
#[test]
775+
#[ignore = "See issue https://github.com/open-telemetry/opentelemetry-rust/issues/1699"]
776+
fn test_instrument_creation() {
777+
let provider = SdkMeterProvider::builder()
778+
.build();
779+
let meter = provider.meter("test");
780+
assert!(meter.u64_counter("test").try_init().is_ok());
781+
let result = meter.u64_counter("test with invalid name").try_init();
782+
// this assert fails, as result is always ok variant.
783+
assert!(result.is_err());
784+
}
773785

774786
#[test]
775787
fn test_instrument_config_validation() {
@@ -787,9 +799,9 @@ mod tests {
787799
("a".repeat(255).leak(), ""),
788800
("a".repeat(256).leak(), INSTRUMENT_NAME_LENGTH),
789801
("invalid name", INSTRUMENT_NAME_INVALID_CHAR),
790-
// hyphens are now valid characters in the specification.
791-
// https://github.com/open-telemetry/opentelemetry-specification/pull/3684
792-
("allow/hyphen", ""),
802+
("allow/slash", ""),
803+
("allow_under_score", ""),
804+
("allow.dots.ok", ""),
793805
];
794806
for (name, expected_error) in instrument_name_test_cases {
795807
let assert = |result: Result<_, MetricsError>| {
@@ -865,6 +877,9 @@ mod tests {
865877
),
866878
("utf8char锈", INSTRUMENT_UNIT_INVALID_CHAR),
867879
("kb", ""),
880+
("Kb/sec", ""),
881+
("%", ""),
882+
("", ""),
868883
];
869884

870885
for (unit, expected_error) in instrument_unit_test_cases {

opentelemetry/src/metrics/noop.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//! # No-op OpenTelemetry Metrics Implementation
22
//!
3-
//! This implementation is returned as the global Meter if no `Meter`
4-
//! has been set. It is also useful for testing purposes as it is intended
5-
//! to have minimal resource utilization and runtime impact.
3+
//! This implementation is returned as the global Meter if no `MeterProvider`
4+
//! has been set. It is expected to have minimal resource utilization and
5+
//! runtime impact.
66
use crate::{
77
metrics::{
88
AsyncInstrument, CallbackRegistration, InstrumentProvider, Meter, MeterProvider, Observer,

0 commit comments

Comments
 (0)