Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate examples #300

Merged
merged 19 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 39 additions & 38 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 42 additions & 3 deletions crates/weaver_common/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,32 @@
//! A generic diagnostic message

use crate::Logger;
use miette::{Diagnostic, LabeledSpan, Report, Severity};
use miette::{Diagnostic, LabeledSpan, MietteDiagnostic, Report, Severity};
use serde::Serialize;
use std::error::Error;
use std::fmt::Debug;
use std::sync::atomic::AtomicBool;

/// A flag to globally enable future mode for diagnostics.
/// When enabled, all the warning messages will be treated as errors.
static FUTURE_MODE: AtomicBool = AtomicBool::new(false);

/// Enable future mode for diagnostics.
/// When enabled, all the warning messages will be treated as errors.
pub fn enable_future_mode() {
FUTURE_MODE.store(true, std::sync::atomic::Ordering::Relaxed);
}

/// Disable future mode for diagnostics.
/// When disabled, all the warning messages will be treated as warnings.
pub fn disable_future_mode() {
FUTURE_MODE.store(false, std::sync::atomic::Ordering::Relaxed);
}

/// Returns true if future mode is enabled for diagnostics.
pub fn is_future_mode_enabled() -> bool {
FUTURE_MODE.load(std::sync::atomic::Ordering::Relaxed)
}

/// An extension to the [`miette::Diagnostic`] struct that adds an ansi message
/// representation of the diagnostic message.
Expand Down Expand Up @@ -58,14 +81,30 @@ impl DiagnosticMessage {
let json_error = serde_json::to_value(&error).expect("Failed to serialize error");
let message = error.to_string();
let code = error.code().map(|error_code| error_code.to_string());
let severity = error.severity();
let mut severity = error.severity();
let help = error.help().map(|help| help.to_string());
let url = error.url().map(|url| url.to_string());
let labels = error.labels().map(|labels| labels.collect());
let ansi_message = format!(
"{:?}",
if is_future_mode_enabled() {
severity = Some(Severity::Error);
Report::new(MietteDiagnostic {
message: message.clone(),
code: code.clone(),
severity,
help: help.clone(),
url: url.clone(),
labels: labels.clone(),
})
} else {
Report::new(error)
}
);

let diagnostic = MietteDiagnosticExt {
message,
ansi_message: format!("{:?}", Report::new(error)),
ansi_message,
code,
severity,
help,
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ groups:
type: string[]
brief: >
Key(s) of message, another way to mark message besides message id.
examples: ["keyA", "keyB"]
examples: [["keyA"], ["keyB"]]
- id: rocketmq.message.tag
type: string
brief: >
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,30 @@
"name": "messaging.batch.message_count",
"type": "int",
"brief": "The number of messages sent, received, or processed in the scope of the batching operation.",
"examples": [
0,
1,
2
],
"examples": [0, 1, 2],
"requirement_level": "recommended",
"note": "Instrumentations SHOULD NOT set `messaging.batch.message_count` on spans that operate with a single message. When a messaging client library supports both batch and single-message API for the same operation, instrumentations SHOULD use `messaging.batch.message_count` for batching APIs and SHOULD NOT use it for single-message APIs.\n"
},
{
"name": "messaging.client_id",
"type": "string",
"brief": "A unique identifier for the client that consumes or produces a message.\n",
"examples": [
"client-5",
"myhost@8742@s8083jm"
],
"examples": ["client-5", "myhost@8742@s8083jm"],
"requirement_level": "recommended"
},
{
"name": "messaging.destination.name",
"type": "string",
"brief": "The message destination name",
"examples": [
"MyQueue",
"MyTopic"
],
"examples": ["MyQueue", "MyTopic"],
"requirement_level": "recommended",
"note": "Destination name SHOULD uniquely identify a specific queue, topic or other entity within the broker. If\nthe broker doesn't have such notion, the destination name SHOULD uniquely identify the broker.\n"
},
{
"name": "messaging.destination.template",
"type": "string",
"brief": "Low cardinality representation of the messaging destination name",
"examples": [
"/customers/{customerId}"
],
"examples": ["/customers/{customerId}"],
"requirement_level": "recommended",
"note": "Destination names could be constructed from templates. An example would be a destination name involving a user name or product id. Although the destination name in this case is of high cardinality, the underlying template is of low cardinality and can be effectively used for grouping and aggregation.\n"
},
Expand All @@ -64,10 +52,7 @@
"name": "messaging.destination_publish.name",
"type": "string",
"brief": "The name of the original destination the message was published to",
"examples": [
"MyQueue",
"MyTopic"
],
"examples": ["MyQueue", "MyTopic"],
"requirement_level": "recommended",
"note": "The name SHOULD uniquely identify a specific queue, topic, or other entity within the broker. If\nthe broker doesn't have such notion, the original destination name SHOULD uniquely identify the broker.\n"
},
Expand Down Expand Up @@ -232,10 +217,7 @@
"name": "messaging.rocketmq.message.keys",
"type": "string[]",
"brief": "Key(s) of message, another way to mark message besides message id.\n",
"examples": [
"keyA",
"keyB"
],
"examples": [["keyA"], ["keyB"]],
"requirement_level": "recommended"
},
{
Expand Down Expand Up @@ -367,10 +349,7 @@
"name": "messaging.destination.name",
"type": "string",
"brief": "The message destination name",
"examples": [
"MyQueue",
"MyTopic"
],
"examples": ["MyQueue", "MyTopic"],
"requirement_level": {
"conditionally_required": "if and only if `messaging.destination.name` is known to have low cardinality. Otherwise, `messaging.destination.template` MAY be populated."
},
Expand All @@ -380,12 +359,10 @@
"name": "messaging.destination.template",
"type": "string",
"brief": "Low cardinality representation of the messaging destination name",
"examples": [
"/customers/{customerId}"
],
"examples": ["/customers/{customerId}"],
"requirement_level": {
"conditionally_required": "if available."
},
"note": "Destination names could be constructed from templates. An example would be a destination name involving a user name or product id. Although the destination name in this case is of high cardinality, the underlying template is of low cardinality and can be effectively used for grouping and aggregation.\n"
}
]
]
Loading
Loading