id
stringlengths 20
153
| type
stringclasses 1
value | granularity
stringclasses 14
values | content
stringlengths 16
84.3k
| metadata
dict |
|---|---|---|---|---|
connector-service_snippet_4018572258718428657_75_15
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
}
/// Extract lineage fields from header
pub fn extract_lineage_fields_from_metadata(
metadata: &metadata::MetadataMap,
config: &configs::LineageConfig,
) -> LineageIds<'static> {
if !config.enabled {
return LineageIds::empty(&config.field_prefix).to_owned();
}
metadata
.get(&config.header_name)
.and_then(|value| value.to_str().ok())
.map(|header_value| LineageIds::new(&config.field_prefix, header_value))
.transpose()
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 75,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_75_30
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
}
/// Extract lineage fields from header
pub fn extract_lineage_fields_from_metadata(
metadata: &metadata::MetadataMap,
config: &configs::LineageConfig,
) -> LineageIds<'static> {
if !config.enabled {
return LineageIds::empty(&config.field_prefix).to_owned();
}
metadata
.get(&config.header_name)
.and_then(|value| value.to_str().ok())
.map(|header_value| LineageIds::new(&config.field_prefix, header_value))
.transpose()
.inspect(|value| {
tracing::info!(
parsed_fields = ?value,
"Successfully parsed lineage header"
)
})
.inspect_err(|err| {
tracing::warn!(
error = %err,
"Failed to parse lineage header, continuing without lineage fields"
)
})
.ok()
.flatten()
.unwrap_or_else(|| LineageIds::empty(&config.field_prefix))
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 75,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_75_50
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
}
/// Extract lineage fields from header
pub fn extract_lineage_fields_from_metadata(
metadata: &metadata::MetadataMap,
config: &configs::LineageConfig,
) -> LineageIds<'static> {
if !config.enabled {
return LineageIds::empty(&config.field_prefix).to_owned();
}
metadata
.get(&config.header_name)
.and_then(|value| value.to_str().ok())
.map(|header_value| LineageIds::new(&config.field_prefix, header_value))
.transpose()
.inspect(|value| {
tracing::info!(
parsed_fields = ?value,
"Successfully parsed lineage header"
)
})
.inspect_err(|err| {
tracing::warn!(
error = %err,
"Failed to parse lineage header, continuing without lineage fields"
)
})
.ok()
.flatten()
.unwrap_or_else(|| LineageIds::empty(&config.field_prefix))
.to_owned()
}
/// Record the header's fields in request's trace
pub fn record_fields_from_header<B: hyper::body::Body>(request: &Request<B>) -> tracing::Span {
let url_path = request.uri().path();
let span = tracing::debug_span!(
"request",
uri = %url_path,
version = ?request.version(),
tenant_id = tracing::field::Empty,
request_id = tracing::field::Empty,
);
request
.headers()
.get(consts::X_TENANT_ID)
.and_then(|value| value.to_str().ok())
.map(|tenant_id| span.record("tenant_id", tenant_id));
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 75,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_100_15
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
)
})
.ok()
.flatten()
.unwrap_or_else(|| LineageIds::empty(&config.field_prefix))
.to_owned()
}
/// Record the header's fields in request's trace
pub fn record_fields_from_header<B: hyper::body::Body>(request: &Request<B>) -> tracing::Span {
let url_path = request.uri().path();
let span = tracing::debug_span!(
"request",
uri = %url_path,
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 100,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_100_30
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
)
})
.ok()
.flatten()
.unwrap_or_else(|| LineageIds::empty(&config.field_prefix))
.to_owned()
}
/// Record the header's fields in request's trace
pub fn record_fields_from_header<B: hyper::body::Body>(request: &Request<B>) -> tracing::Span {
let url_path = request.uri().path();
let span = tracing::debug_span!(
"request",
uri = %url_path,
version = ?request.version(),
tenant_id = tracing::field::Empty,
request_id = tracing::field::Empty,
);
request
.headers()
.get(consts::X_TENANT_ID)
.and_then(|value| value.to_str().ok())
.map(|tenant_id| span.record("tenant_id", tenant_id));
request
.headers()
.get(consts::X_REQUEST_ID)
.and_then(|value| value.to_str().ok())
.map(|request_id| span.record("request_id", request_id));
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 100,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_100_50
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
)
})
.ok()
.flatten()
.unwrap_or_else(|| LineageIds::empty(&config.field_prefix))
.to_owned()
}
/// Record the header's fields in request's trace
pub fn record_fields_from_header<B: hyper::body::Body>(request: &Request<B>) -> tracing::Span {
let url_path = request.uri().path();
let span = tracing::debug_span!(
"request",
uri = %url_path,
version = ?request.version(),
tenant_id = tracing::field::Empty,
request_id = tracing::field::Empty,
);
request
.headers()
.get(consts::X_TENANT_ID)
.and_then(|value| value.to_str().ok())
.map(|tenant_id| span.record("tenant_id", tenant_id));
request
.headers()
.get(consts::X_REQUEST_ID)
.and_then(|value| value.to_str().ok())
.map(|request_id| span.record("request_id", request_id));
span
}
/// Struct to hold extracted metadata payload
///
/// SECURITY WARNING: This struct should only contain non-sensitive business metadata.
/// For any sensitive data (API keys, tokens, credentials, etc.), always:
/// 1. Wrap in hyperswitch_masking::Secret<T>
/// 2. Extract via MaskedMetadata methods instead of adding here
///
#[derive(Clone, Debug)]
pub struct MetadataPayload {
pub tenant_id: String,
pub request_id: String,
pub merchant_id: String,
pub connector: connector_types::ConnectorEnum,
pub lineage_ids: LineageIds<'static>,
pub connector_auth_type: ConnectorAuthType,
pub reference_id: Option<String>,
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 100,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_125_15
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
request
.headers()
.get(consts::X_REQUEST_ID)
.and_then(|value| value.to_str().ok())
.map(|request_id| span.record("request_id", request_id));
span
}
/// Struct to hold extracted metadata payload
///
/// SECURITY WARNING: This struct should only contain non-sensitive business metadata.
/// For any sensitive data (API keys, tokens, credentials, etc.), always:
/// 1. Wrap in hyperswitch_masking::Secret<T>
/// 2. Extract via MaskedMetadata methods instead of adding here
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 125,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_125_30
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
request
.headers()
.get(consts::X_REQUEST_ID)
.and_then(|value| value.to_str().ok())
.map(|request_id| span.record("request_id", request_id));
span
}
/// Struct to hold extracted metadata payload
///
/// SECURITY WARNING: This struct should only contain non-sensitive business metadata.
/// For any sensitive data (API keys, tokens, credentials, etc.), always:
/// 1. Wrap in hyperswitch_masking::Secret<T>
/// 2. Extract via MaskedMetadata methods instead of adding here
///
#[derive(Clone, Debug)]
pub struct MetadataPayload {
pub tenant_id: String,
pub request_id: String,
pub merchant_id: String,
pub connector: connector_types::ConnectorEnum,
pub lineage_ids: LineageIds<'static>,
pub connector_auth_type: ConnectorAuthType,
pub reference_id: Option<String>,
pub shadow_mode: bool,
}
pub fn get_metadata_payload(
metadata: &metadata::MetadataMap,
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 125,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_125_50
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
request
.headers()
.get(consts::X_REQUEST_ID)
.and_then(|value| value.to_str().ok())
.map(|request_id| span.record("request_id", request_id));
span
}
/// Struct to hold extracted metadata payload
///
/// SECURITY WARNING: This struct should only contain non-sensitive business metadata.
/// For any sensitive data (API keys, tokens, credentials, etc.), always:
/// 1. Wrap in hyperswitch_masking::Secret<T>
/// 2. Extract via MaskedMetadata methods instead of adding here
///
#[derive(Clone, Debug)]
pub struct MetadataPayload {
pub tenant_id: String,
pub request_id: String,
pub merchant_id: String,
pub connector: connector_types::ConnectorEnum,
pub lineage_ids: LineageIds<'static>,
pub connector_auth_type: ConnectorAuthType,
pub reference_id: Option<String>,
pub shadow_mode: bool,
}
pub fn get_metadata_payload(
metadata: &metadata::MetadataMap,
server_config: Arc<configs::Config>,
) -> CustomResult<MetadataPayload, ApplicationErrorResponse> {
let connector = connector_from_metadata(metadata)?;
let merchant_id = merchant_id_from_metadata(metadata)?;
let tenant_id = tenant_id_from_metadata(metadata)?;
let request_id = request_id_from_metadata(metadata)?;
let lineage_ids = extract_lineage_fields_from_metadata(metadata, &server_config.lineage);
let connector_auth_type = auth_from_metadata(metadata)?;
let reference_id = reference_id_from_metadata(metadata)?;
let shadow_mode = shadow_mode_from_metadata(metadata);
Ok(MetadataPayload {
tenant_id,
request_id,
merchant_id,
connector,
lineage_ids,
connector_auth_type,
reference_id,
shadow_mode,
})
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 125,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_150_15
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
pub shadow_mode: bool,
}
pub fn get_metadata_payload(
metadata: &metadata::MetadataMap,
server_config: Arc<configs::Config>,
) -> CustomResult<MetadataPayload, ApplicationErrorResponse> {
let connector = connector_from_metadata(metadata)?;
let merchant_id = merchant_id_from_metadata(metadata)?;
let tenant_id = tenant_id_from_metadata(metadata)?;
let request_id = request_id_from_metadata(metadata)?;
let lineage_ids = extract_lineage_fields_from_metadata(metadata, &server_config.lineage);
let connector_auth_type = auth_from_metadata(metadata)?;
let reference_id = reference_id_from_metadata(metadata)?;
let shadow_mode = shadow_mode_from_metadata(metadata);
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 150,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_150_30
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
pub shadow_mode: bool,
}
pub fn get_metadata_payload(
metadata: &metadata::MetadataMap,
server_config: Arc<configs::Config>,
) -> CustomResult<MetadataPayload, ApplicationErrorResponse> {
let connector = connector_from_metadata(metadata)?;
let merchant_id = merchant_id_from_metadata(metadata)?;
let tenant_id = tenant_id_from_metadata(metadata)?;
let request_id = request_id_from_metadata(metadata)?;
let lineage_ids = extract_lineage_fields_from_metadata(metadata, &server_config.lineage);
let connector_auth_type = auth_from_metadata(metadata)?;
let reference_id = reference_id_from_metadata(metadata)?;
let shadow_mode = shadow_mode_from_metadata(metadata);
Ok(MetadataPayload {
tenant_id,
request_id,
merchant_id,
connector,
lineage_ids,
connector_auth_type,
reference_id,
shadow_mode,
})
}
pub fn connector_from_metadata(
metadata: &metadata::MetadataMap,
) -> CustomResult<connector_types::ConnectorEnum, ApplicationErrorResponse> {
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 150,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_150_50
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
pub shadow_mode: bool,
}
pub fn get_metadata_payload(
metadata: &metadata::MetadataMap,
server_config: Arc<configs::Config>,
) -> CustomResult<MetadataPayload, ApplicationErrorResponse> {
let connector = connector_from_metadata(metadata)?;
let merchant_id = merchant_id_from_metadata(metadata)?;
let tenant_id = tenant_id_from_metadata(metadata)?;
let request_id = request_id_from_metadata(metadata)?;
let lineage_ids = extract_lineage_fields_from_metadata(metadata, &server_config.lineage);
let connector_auth_type = auth_from_metadata(metadata)?;
let reference_id = reference_id_from_metadata(metadata)?;
let shadow_mode = shadow_mode_from_metadata(metadata);
Ok(MetadataPayload {
tenant_id,
request_id,
merchant_id,
connector,
lineage_ids,
connector_auth_type,
reference_id,
shadow_mode,
})
}
pub fn connector_from_metadata(
metadata: &metadata::MetadataMap,
) -> CustomResult<connector_types::ConnectorEnum, ApplicationErrorResponse> {
parse_metadata(metadata, consts::X_CONNECTOR_NAME).and_then(|inner| {
connector_types::ConnectorEnum::from_str(inner).map_err(|e| {
Report::new(ApplicationErrorResponse::BadRequest(ApiError {
sub_code: "INVALID_CONNECTOR".to_string(),
error_identifier: 400,
error_message: format!("Invalid connector: {e}"),
error_object: None,
}))
})
})
}
pub fn merchant_id_from_metadata(
metadata: &metadata::MetadataMap,
) -> CustomResult<String, ApplicationErrorResponse> {
parse_metadata(metadata, consts::X_MERCHANT_ID)
.map(|inner| inner.to_string())
.map_err(|e| {
Report::new(ApplicationErrorResponse::BadRequest(ApiError {
sub_code: "MISSING_MERCHANT_ID".to_string(),
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 150,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_175_15
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
}
pub fn connector_from_metadata(
metadata: &metadata::MetadataMap,
) -> CustomResult<connector_types::ConnectorEnum, ApplicationErrorResponse> {
parse_metadata(metadata, consts::X_CONNECTOR_NAME).and_then(|inner| {
connector_types::ConnectorEnum::from_str(inner).map_err(|e| {
Report::new(ApplicationErrorResponse::BadRequest(ApiError {
sub_code: "INVALID_CONNECTOR".to_string(),
error_identifier: 400,
error_message: format!("Invalid connector: {e}"),
error_object: None,
}))
})
})
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 175,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_175_30
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
}
pub fn connector_from_metadata(
metadata: &metadata::MetadataMap,
) -> CustomResult<connector_types::ConnectorEnum, ApplicationErrorResponse> {
parse_metadata(metadata, consts::X_CONNECTOR_NAME).and_then(|inner| {
connector_types::ConnectorEnum::from_str(inner).map_err(|e| {
Report::new(ApplicationErrorResponse::BadRequest(ApiError {
sub_code: "INVALID_CONNECTOR".to_string(),
error_identifier: 400,
error_message: format!("Invalid connector: {e}"),
error_object: None,
}))
})
})
}
pub fn merchant_id_from_metadata(
metadata: &metadata::MetadataMap,
) -> CustomResult<String, ApplicationErrorResponse> {
parse_metadata(metadata, consts::X_MERCHANT_ID)
.map(|inner| inner.to_string())
.map_err(|e| {
Report::new(ApplicationErrorResponse::BadRequest(ApiError {
sub_code: "MISSING_MERCHANT_ID".to_string(),
error_identifier: 400,
error_message: format!("Missing merchant ID in request metadata: {e}"),
error_object: None,
}))
})
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 175,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_175_50
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
}
pub fn connector_from_metadata(
metadata: &metadata::MetadataMap,
) -> CustomResult<connector_types::ConnectorEnum, ApplicationErrorResponse> {
parse_metadata(metadata, consts::X_CONNECTOR_NAME).and_then(|inner| {
connector_types::ConnectorEnum::from_str(inner).map_err(|e| {
Report::new(ApplicationErrorResponse::BadRequest(ApiError {
sub_code: "INVALID_CONNECTOR".to_string(),
error_identifier: 400,
error_message: format!("Invalid connector: {e}"),
error_object: None,
}))
})
})
}
pub fn merchant_id_from_metadata(
metadata: &metadata::MetadataMap,
) -> CustomResult<String, ApplicationErrorResponse> {
parse_metadata(metadata, consts::X_MERCHANT_ID)
.map(|inner| inner.to_string())
.map_err(|e| {
Report::new(ApplicationErrorResponse::BadRequest(ApiError {
sub_code: "MISSING_MERCHANT_ID".to_string(),
error_identifier: 400,
error_message: format!("Missing merchant ID in request metadata: {e}"),
error_object: None,
}))
})
}
pub fn request_id_from_metadata(
metadata: &metadata::MetadataMap,
) -> CustomResult<String, ApplicationErrorResponse> {
parse_metadata(metadata, consts::X_REQUEST_ID)
.map(|inner| inner.to_string())
.map_err(|e| {
Report::new(ApplicationErrorResponse::BadRequest(ApiError {
sub_code: "MISSING_REQUEST_ID".to_string(),
error_identifier: 400,
error_message: format!("Missing request ID in request metadata: {e}"),
error_object: None,
}))
})
}
pub fn tenant_id_from_metadata(
metadata: &metadata::MetadataMap,
) -> CustomResult<String, ApplicationErrorResponse> {
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 175,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_200_15
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
error_identifier: 400,
error_message: format!("Missing merchant ID in request metadata: {e}"),
error_object: None,
}))
})
}
pub fn request_id_from_metadata(
metadata: &metadata::MetadataMap,
) -> CustomResult<String, ApplicationErrorResponse> {
parse_metadata(metadata, consts::X_REQUEST_ID)
.map(|inner| inner.to_string())
.map_err(|e| {
Report::new(ApplicationErrorResponse::BadRequest(ApiError {
sub_code: "MISSING_REQUEST_ID".to_string(),
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 200,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_200_30
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
error_identifier: 400,
error_message: format!("Missing merchant ID in request metadata: {e}"),
error_object: None,
}))
})
}
pub fn request_id_from_metadata(
metadata: &metadata::MetadataMap,
) -> CustomResult<String, ApplicationErrorResponse> {
parse_metadata(metadata, consts::X_REQUEST_ID)
.map(|inner| inner.to_string())
.map_err(|e| {
Report::new(ApplicationErrorResponse::BadRequest(ApiError {
sub_code: "MISSING_REQUEST_ID".to_string(),
error_identifier: 400,
error_message: format!("Missing request ID in request metadata: {e}"),
error_object: None,
}))
})
}
pub fn tenant_id_from_metadata(
metadata: &metadata::MetadataMap,
) -> CustomResult<String, ApplicationErrorResponse> {
parse_metadata(metadata, consts::X_TENANT_ID)
.map(|s| s.to_string())
.or_else(|_| Ok("DefaultTenantId".to_string()))
}
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 200,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_200_50
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
error_identifier: 400,
error_message: format!("Missing merchant ID in request metadata: {e}"),
error_object: None,
}))
})
}
pub fn request_id_from_metadata(
metadata: &metadata::MetadataMap,
) -> CustomResult<String, ApplicationErrorResponse> {
parse_metadata(metadata, consts::X_REQUEST_ID)
.map(|inner| inner.to_string())
.map_err(|e| {
Report::new(ApplicationErrorResponse::BadRequest(ApiError {
sub_code: "MISSING_REQUEST_ID".to_string(),
error_identifier: 400,
error_message: format!("Missing request ID in request metadata: {e}"),
error_object: None,
}))
})
}
pub fn tenant_id_from_metadata(
metadata: &metadata::MetadataMap,
) -> CustomResult<String, ApplicationErrorResponse> {
parse_metadata(metadata, consts::X_TENANT_ID)
.map(|s| s.to_string())
.or_else(|_| Ok("DefaultTenantId".to_string()))
}
pub fn reference_id_from_metadata(
metadata: &metadata::MetadataMap,
) -> CustomResult<Option<String>, ApplicationErrorResponse> {
parse_optional_metadata(metadata, consts::X_REFERENCE_ID).map(|s| s.map(|s| s.to_string()))
}
pub fn shadow_mode_from_metadata(metadata: &metadata::MetadataMap) -> bool {
parse_optional_metadata(metadata, X_SHADOW_MODE)
.ok()
.flatten()
.map(|value| value.to_lowercase() == "true")
.unwrap_or(false)
}
pub fn auth_from_metadata(
metadata: &metadata::MetadataMap,
) -> CustomResult<ConnectorAuthType, ApplicationErrorResponse> {
let auth = parse_metadata(metadata, X_AUTH)?;
#[allow(clippy::wildcard_in_or_patterns)]
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 200,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_225_15
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
parse_metadata(metadata, consts::X_TENANT_ID)
.map(|s| s.to_string())
.or_else(|_| Ok("DefaultTenantId".to_string()))
}
pub fn reference_id_from_metadata(
metadata: &metadata::MetadataMap,
) -> CustomResult<Option<String>, ApplicationErrorResponse> {
parse_optional_metadata(metadata, consts::X_REFERENCE_ID).map(|s| s.map(|s| s.to_string()))
}
pub fn shadow_mode_from_metadata(metadata: &metadata::MetadataMap) -> bool {
parse_optional_metadata(metadata, X_SHADOW_MODE)
.ok()
.flatten()
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 225,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_225_30
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
parse_metadata(metadata, consts::X_TENANT_ID)
.map(|s| s.to_string())
.or_else(|_| Ok("DefaultTenantId".to_string()))
}
pub fn reference_id_from_metadata(
metadata: &metadata::MetadataMap,
) -> CustomResult<Option<String>, ApplicationErrorResponse> {
parse_optional_metadata(metadata, consts::X_REFERENCE_ID).map(|s| s.map(|s| s.to_string()))
}
pub fn shadow_mode_from_metadata(metadata: &metadata::MetadataMap) -> bool {
parse_optional_metadata(metadata, X_SHADOW_MODE)
.ok()
.flatten()
.map(|value| value.to_lowercase() == "true")
.unwrap_or(false)
}
pub fn auth_from_metadata(
metadata: &metadata::MetadataMap,
) -> CustomResult<ConnectorAuthType, ApplicationErrorResponse> {
let auth = parse_metadata(metadata, X_AUTH)?;
#[allow(clippy::wildcard_in_or_patterns)]
match auth {
"header-key" => Ok(ConnectorAuthType::HeaderKey {
api_key: parse_metadata(metadata, X_API_KEY)?.to_string().into(),
}),
"body-key" => Ok(ConnectorAuthType::BodyKey {
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 225,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_225_50
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
parse_metadata(metadata, consts::X_TENANT_ID)
.map(|s| s.to_string())
.or_else(|_| Ok("DefaultTenantId".to_string()))
}
pub fn reference_id_from_metadata(
metadata: &metadata::MetadataMap,
) -> CustomResult<Option<String>, ApplicationErrorResponse> {
parse_optional_metadata(metadata, consts::X_REFERENCE_ID).map(|s| s.map(|s| s.to_string()))
}
pub fn shadow_mode_from_metadata(metadata: &metadata::MetadataMap) -> bool {
parse_optional_metadata(metadata, X_SHADOW_MODE)
.ok()
.flatten()
.map(|value| value.to_lowercase() == "true")
.unwrap_or(false)
}
pub fn auth_from_metadata(
metadata: &metadata::MetadataMap,
) -> CustomResult<ConnectorAuthType, ApplicationErrorResponse> {
let auth = parse_metadata(metadata, X_AUTH)?;
#[allow(clippy::wildcard_in_or_patterns)]
match auth {
"header-key" => Ok(ConnectorAuthType::HeaderKey {
api_key: parse_metadata(metadata, X_API_KEY)?.to_string().into(),
}),
"body-key" => Ok(ConnectorAuthType::BodyKey {
api_key: parse_metadata(metadata, X_API_KEY)?.to_string().into(),
key1: parse_metadata(metadata, X_KEY1)?.to_string().into(),
}),
"signature-key" => Ok(ConnectorAuthType::SignatureKey {
api_key: parse_metadata(metadata, X_API_KEY)?.to_string().into(),
key1: parse_metadata(metadata, X_KEY1)?.to_string().into(),
api_secret: parse_metadata(metadata, X_API_SECRET)?.to_string().into(),
}),
"multi-auth-key" => Ok(ConnectorAuthType::MultiAuthKey {
api_key: parse_metadata(metadata, X_API_KEY)?.to_string().into(),
key1: parse_metadata(metadata, X_KEY1)?.to_string().into(),
key2: parse_metadata(metadata, X_KEY2)?.to_string().into(),
api_secret: parse_metadata(metadata, X_API_SECRET)?.to_string().into(),
}),
"no-key" => Ok(ConnectorAuthType::NoKey),
"temporary-auth" => Ok(ConnectorAuthType::TemporaryAuth),
"currency-auth-key" => {
let auth_key_map_str = parse_metadata(metadata, X_AUTH_KEY_MAP)?;
let auth_key_map: HashMap<
common_enums::enums::Currency,
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 225,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_250_15
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
match auth {
"header-key" => Ok(ConnectorAuthType::HeaderKey {
api_key: parse_metadata(metadata, X_API_KEY)?.to_string().into(),
}),
"body-key" => Ok(ConnectorAuthType::BodyKey {
api_key: parse_metadata(metadata, X_API_KEY)?.to_string().into(),
key1: parse_metadata(metadata, X_KEY1)?.to_string().into(),
}),
"signature-key" => Ok(ConnectorAuthType::SignatureKey {
api_key: parse_metadata(metadata, X_API_KEY)?.to_string().into(),
key1: parse_metadata(metadata, X_KEY1)?.to_string().into(),
api_secret: parse_metadata(metadata, X_API_SECRET)?.to_string().into(),
}),
"multi-auth-key" => Ok(ConnectorAuthType::MultiAuthKey {
api_key: parse_metadata(metadata, X_API_KEY)?.to_string().into(),
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 250,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_250_30
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
match auth {
"header-key" => Ok(ConnectorAuthType::HeaderKey {
api_key: parse_metadata(metadata, X_API_KEY)?.to_string().into(),
}),
"body-key" => Ok(ConnectorAuthType::BodyKey {
api_key: parse_metadata(metadata, X_API_KEY)?.to_string().into(),
key1: parse_metadata(metadata, X_KEY1)?.to_string().into(),
}),
"signature-key" => Ok(ConnectorAuthType::SignatureKey {
api_key: parse_metadata(metadata, X_API_KEY)?.to_string().into(),
key1: parse_metadata(metadata, X_KEY1)?.to_string().into(),
api_secret: parse_metadata(metadata, X_API_SECRET)?.to_string().into(),
}),
"multi-auth-key" => Ok(ConnectorAuthType::MultiAuthKey {
api_key: parse_metadata(metadata, X_API_KEY)?.to_string().into(),
key1: parse_metadata(metadata, X_KEY1)?.to_string().into(),
key2: parse_metadata(metadata, X_KEY2)?.to_string().into(),
api_secret: parse_metadata(metadata, X_API_SECRET)?.to_string().into(),
}),
"no-key" => Ok(ConnectorAuthType::NoKey),
"temporary-auth" => Ok(ConnectorAuthType::TemporaryAuth),
"currency-auth-key" => {
let auth_key_map_str = parse_metadata(metadata, X_AUTH_KEY_MAP)?;
let auth_key_map: HashMap<
common_enums::enums::Currency,
common_utils::pii::SecretSerdeValue,
> = serde_json::from_str(auth_key_map_str).change_context(
ApplicationErrorResponse::BadRequest(ApiError {
sub_code: "INVALID_AUTH_KEY_MAP".to_string(),
error_identifier: 400,
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 250,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_250_50
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
match auth {
"header-key" => Ok(ConnectorAuthType::HeaderKey {
api_key: parse_metadata(metadata, X_API_KEY)?.to_string().into(),
}),
"body-key" => Ok(ConnectorAuthType::BodyKey {
api_key: parse_metadata(metadata, X_API_KEY)?.to_string().into(),
key1: parse_metadata(metadata, X_KEY1)?.to_string().into(),
}),
"signature-key" => Ok(ConnectorAuthType::SignatureKey {
api_key: parse_metadata(metadata, X_API_KEY)?.to_string().into(),
key1: parse_metadata(metadata, X_KEY1)?.to_string().into(),
api_secret: parse_metadata(metadata, X_API_SECRET)?.to_string().into(),
}),
"multi-auth-key" => Ok(ConnectorAuthType::MultiAuthKey {
api_key: parse_metadata(metadata, X_API_KEY)?.to_string().into(),
key1: parse_metadata(metadata, X_KEY1)?.to_string().into(),
key2: parse_metadata(metadata, X_KEY2)?.to_string().into(),
api_secret: parse_metadata(metadata, X_API_SECRET)?.to_string().into(),
}),
"no-key" => Ok(ConnectorAuthType::NoKey),
"temporary-auth" => Ok(ConnectorAuthType::TemporaryAuth),
"currency-auth-key" => {
let auth_key_map_str = parse_metadata(metadata, X_AUTH_KEY_MAP)?;
let auth_key_map: HashMap<
common_enums::enums::Currency,
common_utils::pii::SecretSerdeValue,
> = serde_json::from_str(auth_key_map_str).change_context(
ApplicationErrorResponse::BadRequest(ApiError {
sub_code: "INVALID_AUTH_KEY_MAP".to_string(),
error_identifier: 400,
error_message: "Invalid auth-key-map format".to_string(),
error_object: None,
}),
)?;
Ok(ConnectorAuthType::CurrencyAuthKey { auth_key_map })
}
"certificate-auth" | _ => Err(Report::new(ApplicationErrorResponse::BadRequest(
ApiError {
sub_code: "INVALID_AUTH_TYPE".to_string(),
error_identifier: 400,
error_message: format!("Invalid auth type: {auth}"),
error_object: None,
},
))),
}
}
fn parse_metadata<'a>(
metadata: &'a metadata::MetadataMap,
key: &str,
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 250,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_275_15
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
common_utils::pii::SecretSerdeValue,
> = serde_json::from_str(auth_key_map_str).change_context(
ApplicationErrorResponse::BadRequest(ApiError {
sub_code: "INVALID_AUTH_KEY_MAP".to_string(),
error_identifier: 400,
error_message: "Invalid auth-key-map format".to_string(),
error_object: None,
}),
)?;
Ok(ConnectorAuthType::CurrencyAuthKey { auth_key_map })
}
"certificate-auth" | _ => Err(Report::new(ApplicationErrorResponse::BadRequest(
ApiError {
sub_code: "INVALID_AUTH_TYPE".to_string(),
error_identifier: 400,
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 275,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_275_30
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
common_utils::pii::SecretSerdeValue,
> = serde_json::from_str(auth_key_map_str).change_context(
ApplicationErrorResponse::BadRequest(ApiError {
sub_code: "INVALID_AUTH_KEY_MAP".to_string(),
error_identifier: 400,
error_message: "Invalid auth-key-map format".to_string(),
error_object: None,
}),
)?;
Ok(ConnectorAuthType::CurrencyAuthKey { auth_key_map })
}
"certificate-auth" | _ => Err(Report::new(ApplicationErrorResponse::BadRequest(
ApiError {
sub_code: "INVALID_AUTH_TYPE".to_string(),
error_identifier: 400,
error_message: format!("Invalid auth type: {auth}"),
error_object: None,
},
))),
}
}
fn parse_metadata<'a>(
metadata: &'a metadata::MetadataMap,
key: &str,
) -> CustomResult<&'a str, ApplicationErrorResponse> {
metadata
.get(key)
.ok_or_else(|| {
Report::new(ApplicationErrorResponse::BadRequest(ApiError {
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 275,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_275_50
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
common_utils::pii::SecretSerdeValue,
> = serde_json::from_str(auth_key_map_str).change_context(
ApplicationErrorResponse::BadRequest(ApiError {
sub_code: "INVALID_AUTH_KEY_MAP".to_string(),
error_identifier: 400,
error_message: "Invalid auth-key-map format".to_string(),
error_object: None,
}),
)?;
Ok(ConnectorAuthType::CurrencyAuthKey { auth_key_map })
}
"certificate-auth" | _ => Err(Report::new(ApplicationErrorResponse::BadRequest(
ApiError {
sub_code: "INVALID_AUTH_TYPE".to_string(),
error_identifier: 400,
error_message: format!("Invalid auth type: {auth}"),
error_object: None,
},
))),
}
}
fn parse_metadata<'a>(
metadata: &'a metadata::MetadataMap,
key: &str,
) -> CustomResult<&'a str, ApplicationErrorResponse> {
metadata
.get(key)
.ok_or_else(|| {
Report::new(ApplicationErrorResponse::BadRequest(ApiError {
sub_code: "MISSING_METADATA".to_string(),
error_identifier: 400,
error_message: format!("Missing {key} in request metadata"),
error_object: None,
}))
})
.and_then(|value| {
value.to_str().map_err(|e| {
Report::new(ApplicationErrorResponse::BadRequest(ApiError {
sub_code: "INVALID_METADATA".to_string(),
error_identifier: 400,
error_message: format!("Invalid {key} in request metadata: {e}"),
error_object: None,
}))
})
})
}
fn parse_optional_metadata<'a>(
metadata: &'a metadata::MetadataMap,
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 275,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_300_15
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
) -> CustomResult<&'a str, ApplicationErrorResponse> {
metadata
.get(key)
.ok_or_else(|| {
Report::new(ApplicationErrorResponse::BadRequest(ApiError {
sub_code: "MISSING_METADATA".to_string(),
error_identifier: 400,
error_message: format!("Missing {key} in request metadata"),
error_object: None,
}))
})
.and_then(|value| {
value.to_str().map_err(|e| {
Report::new(ApplicationErrorResponse::BadRequest(ApiError {
sub_code: "INVALID_METADATA".to_string(),
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 300,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_300_30
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
) -> CustomResult<&'a str, ApplicationErrorResponse> {
metadata
.get(key)
.ok_or_else(|| {
Report::new(ApplicationErrorResponse::BadRequest(ApiError {
sub_code: "MISSING_METADATA".to_string(),
error_identifier: 400,
error_message: format!("Missing {key} in request metadata"),
error_object: None,
}))
})
.and_then(|value| {
value.to_str().map_err(|e| {
Report::new(ApplicationErrorResponse::BadRequest(ApiError {
sub_code: "INVALID_METADATA".to_string(),
error_identifier: 400,
error_message: format!("Invalid {key} in request metadata: {e}"),
error_object: None,
}))
})
})
}
fn parse_optional_metadata<'a>(
metadata: &'a metadata::MetadataMap,
key: &str,
) -> CustomResult<Option<&'a str>, ApplicationErrorResponse> {
metadata
.get(key)
.map(|value| value.to_str())
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 300,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_300_50
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
) -> CustomResult<&'a str, ApplicationErrorResponse> {
metadata
.get(key)
.ok_or_else(|| {
Report::new(ApplicationErrorResponse::BadRequest(ApiError {
sub_code: "MISSING_METADATA".to_string(),
error_identifier: 400,
error_message: format!("Missing {key} in request metadata"),
error_object: None,
}))
})
.and_then(|value| {
value.to_str().map_err(|e| {
Report::new(ApplicationErrorResponse::BadRequest(ApiError {
sub_code: "INVALID_METADATA".to_string(),
error_identifier: 400,
error_message: format!("Invalid {key} in request metadata: {e}"),
error_object: None,
}))
})
})
}
fn parse_optional_metadata<'a>(
metadata: &'a metadata::MetadataMap,
key: &str,
) -> CustomResult<Option<&'a str>, ApplicationErrorResponse> {
metadata
.get(key)
.map(|value| value.to_str())
.transpose()
.map_err(|e| {
Report::new(ApplicationErrorResponse::BadRequest(ApiError {
sub_code: "INVALID_METADATA".to_string(),
error_identifier: 400,
error_message: format!("Invalid {key} in request metadata: {e}"),
error_object: None,
}))
})
}
pub fn log_before_initialization<T>(
request_data: &RequestData<T>,
service_name: &str,
) -> CustomResult<(), ApplicationErrorResponse>
where
T: serde::Serialize,
{
let metadata_payload = &request_data.extracted_metadata;
let MetadataPayload {
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 300,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_325_15
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
key: &str,
) -> CustomResult<Option<&'a str>, ApplicationErrorResponse> {
metadata
.get(key)
.map(|value| value.to_str())
.transpose()
.map_err(|e| {
Report::new(ApplicationErrorResponse::BadRequest(ApiError {
sub_code: "INVALID_METADATA".to_string(),
error_identifier: 400,
error_message: format!("Invalid {key} in request metadata: {e}"),
error_object: None,
}))
})
}
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 325,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_325_30
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
key: &str,
) -> CustomResult<Option<&'a str>, ApplicationErrorResponse> {
metadata
.get(key)
.map(|value| value.to_str())
.transpose()
.map_err(|e| {
Report::new(ApplicationErrorResponse::BadRequest(ApiError {
sub_code: "INVALID_METADATA".to_string(),
error_identifier: 400,
error_message: format!("Invalid {key} in request metadata: {e}"),
error_object: None,
}))
})
}
pub fn log_before_initialization<T>(
request_data: &RequestData<T>,
service_name: &str,
) -> CustomResult<(), ApplicationErrorResponse>
where
T: serde::Serialize,
{
let metadata_payload = &request_data.extracted_metadata;
let MetadataPayload {
connector,
merchant_id,
tenant_id,
request_id,
..
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 325,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_325_50
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
key: &str,
) -> CustomResult<Option<&'a str>, ApplicationErrorResponse> {
metadata
.get(key)
.map(|value| value.to_str())
.transpose()
.map_err(|e| {
Report::new(ApplicationErrorResponse::BadRequest(ApiError {
sub_code: "INVALID_METADATA".to_string(),
error_identifier: 400,
error_message: format!("Invalid {key} in request metadata: {e}"),
error_object: None,
}))
})
}
pub fn log_before_initialization<T>(
request_data: &RequestData<T>,
service_name: &str,
) -> CustomResult<(), ApplicationErrorResponse>
where
T: serde::Serialize,
{
let metadata_payload = &request_data.extracted_metadata;
let MetadataPayload {
connector,
merchant_id,
tenant_id,
request_id,
..
} = metadata_payload;
let current_span = tracing::Span::current();
let req_body_json = match hyperswitch_masking::masked_serialize(&request_data.payload) {
Ok(masked_value) => masked_value.to_string(),
Err(e) => {
tracing::error!("Masked serialization error: {:?}", e);
"<masked serialization error>".to_string()
}
};
current_span.record("service_name", service_name);
current_span.record("request_body", req_body_json);
current_span.record("gateway", connector.to_string());
current_span.record("merchant_id", merchant_id);
current_span.record("tenant_id", tenant_id);
current_span.record("request_id", request_id);
tracing::info!("Golden Log Line (incoming)");
Ok(())
}
pub fn log_after_initialization<T>(result: &Result<tonic::Response<T>, tonic::Status>)
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 325,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_350_15
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
connector,
merchant_id,
tenant_id,
request_id,
..
} = metadata_payload;
let current_span = tracing::Span::current();
let req_body_json = match hyperswitch_masking::masked_serialize(&request_data.payload) {
Ok(masked_value) => masked_value.to_string(),
Err(e) => {
tracing::error!("Masked serialization error: {:?}", e);
"<masked serialization error>".to_string()
}
};
current_span.record("service_name", service_name);
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 350,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_350_30
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
connector,
merchant_id,
tenant_id,
request_id,
..
} = metadata_payload;
let current_span = tracing::Span::current();
let req_body_json = match hyperswitch_masking::masked_serialize(&request_data.payload) {
Ok(masked_value) => masked_value.to_string(),
Err(e) => {
tracing::error!("Masked serialization error: {:?}", e);
"<masked serialization error>".to_string()
}
};
current_span.record("service_name", service_name);
current_span.record("request_body", req_body_json);
current_span.record("gateway", connector.to_string());
current_span.record("merchant_id", merchant_id);
current_span.record("tenant_id", tenant_id);
current_span.record("request_id", request_id);
tracing::info!("Golden Log Line (incoming)");
Ok(())
}
pub fn log_after_initialization<T>(result: &Result<tonic::Response<T>, tonic::Status>)
where
T: serde::Serialize + std::fmt::Debug,
{
let current_span = tracing::Span::current();
// let duration = start_time.elapsed().as_millis();
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 350,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_350_50
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
connector,
merchant_id,
tenant_id,
request_id,
..
} = metadata_payload;
let current_span = tracing::Span::current();
let req_body_json = match hyperswitch_masking::masked_serialize(&request_data.payload) {
Ok(masked_value) => masked_value.to_string(),
Err(e) => {
tracing::error!("Masked serialization error: {:?}", e);
"<masked serialization error>".to_string()
}
};
current_span.record("service_name", service_name);
current_span.record("request_body", req_body_json);
current_span.record("gateway", connector.to_string());
current_span.record("merchant_id", merchant_id);
current_span.record("tenant_id", tenant_id);
current_span.record("request_id", request_id);
tracing::info!("Golden Log Line (incoming)");
Ok(())
}
pub fn log_after_initialization<T>(result: &Result<tonic::Response<T>, tonic::Status>)
where
T: serde::Serialize + std::fmt::Debug,
{
let current_span = tracing::Span::current();
// let duration = start_time.elapsed().as_millis();
// current_span.record("response_time", duration);
match &result {
Ok(response) => {
current_span.record("response_body", tracing::field::debug(response.get_ref()));
let res_ref = response.get_ref();
// Try converting to JSON Value
if let Ok(serde_json::Value::Object(map)) = serde_json::to_value(res_ref) {
if let Some(status_val) = map.get("status") {
let status_num_opt = status_val.as_number();
let status_u32_opt: Option<u32> = status_num_opt
.and_then(|n| n.as_u64())
.and_then(|n| u32::try_from(n).ok());
let status_str = if let Some(s) = status_u32_opt {
common_enums::AttemptStatus::try_from(s)
.unwrap_or(common_enums::AttemptStatus::Unknown)
.to_string()
} else {
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 350,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_375_15
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
where
T: serde::Serialize + std::fmt::Debug,
{
let current_span = tracing::Span::current();
// let duration = start_time.elapsed().as_millis();
// current_span.record("response_time", duration);
match &result {
Ok(response) => {
current_span.record("response_body", tracing::field::debug(response.get_ref()));
let res_ref = response.get_ref();
// Try converting to JSON Value
if let Ok(serde_json::Value::Object(map)) = serde_json::to_value(res_ref) {
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 375,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_375_30
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
where
T: serde::Serialize + std::fmt::Debug,
{
let current_span = tracing::Span::current();
// let duration = start_time.elapsed().as_millis();
// current_span.record("response_time", duration);
match &result {
Ok(response) => {
current_span.record("response_body", tracing::field::debug(response.get_ref()));
let res_ref = response.get_ref();
// Try converting to JSON Value
if let Ok(serde_json::Value::Object(map)) = serde_json::to_value(res_ref) {
if let Some(status_val) = map.get("status") {
let status_num_opt = status_val.as_number();
let status_u32_opt: Option<u32> = status_num_opt
.and_then(|n| n.as_u64())
.and_then(|n| u32::try_from(n).ok());
let status_str = if let Some(s) = status_u32_opt {
common_enums::AttemptStatus::try_from(s)
.unwrap_or(common_enums::AttemptStatus::Unknown)
.to_string()
} else {
common_enums::AttemptStatus::Unknown.to_string()
};
current_span.record("flow_specific_fields.status", status_str);
}
} else {
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 375,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_375_50
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
where
T: serde::Serialize + std::fmt::Debug,
{
let current_span = tracing::Span::current();
// let duration = start_time.elapsed().as_millis();
// current_span.record("response_time", duration);
match &result {
Ok(response) => {
current_span.record("response_body", tracing::field::debug(response.get_ref()));
let res_ref = response.get_ref();
// Try converting to JSON Value
if let Ok(serde_json::Value::Object(map)) = serde_json::to_value(res_ref) {
if let Some(status_val) = map.get("status") {
let status_num_opt = status_val.as_number();
let status_u32_opt: Option<u32> = status_num_opt
.and_then(|n| n.as_u64())
.and_then(|n| u32::try_from(n).ok());
let status_str = if let Some(s) = status_u32_opt {
common_enums::AttemptStatus::try_from(s)
.unwrap_or(common_enums::AttemptStatus::Unknown)
.to_string()
} else {
common_enums::AttemptStatus::Unknown.to_string()
};
current_span.record("flow_specific_fields.status", status_str);
}
} else {
tracing::warn!("Could not serialize response to JSON to extract status");
}
}
Err(status) => {
current_span.record("error_message", status.message());
current_span.record("status_code", status.code().to_string());
}
}
tracing::info!("Golden Log Line (incoming)");
}
pub async fn grpc_logging_wrapper<T, F, Fut, R>(
request: tonic::Request<T>,
service_name: &str,
config: Arc<configs::Config>,
flow_name: FlowName,
handler: F,
) -> Result<tonic::Response<R>, tonic::Status>
where
T: serde::Serialize
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 375,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_400_15
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
common_enums::AttemptStatus::Unknown.to_string()
};
current_span.record("flow_specific_fields.status", status_str);
}
} else {
tracing::warn!("Could not serialize response to JSON to extract status");
}
}
Err(status) => {
current_span.record("error_message", status.message());
current_span.record("status_code", status.code().to_string());
}
}
tracing::info!("Golden Log Line (incoming)");
}
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 400,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_400_30
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
common_enums::AttemptStatus::Unknown.to_string()
};
current_span.record("flow_specific_fields.status", status_str);
}
} else {
tracing::warn!("Could not serialize response to JSON to extract status");
}
}
Err(status) => {
current_span.record("error_message", status.message());
current_span.record("status_code", status.code().to_string());
}
}
tracing::info!("Golden Log Line (incoming)");
}
pub async fn grpc_logging_wrapper<T, F, Fut, R>(
request: tonic::Request<T>,
service_name: &str,
config: Arc<configs::Config>,
flow_name: FlowName,
handler: F,
) -> Result<tonic::Response<R>, tonic::Status>
where
T: serde::Serialize
+ std::fmt::Debug
+ Send
+ 'static
+ hyperswitch_masking::ErasedMaskSerialize,
F: FnOnce(RequestData<T>) -> Fut + Send,
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 400,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_400_50
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
common_enums::AttemptStatus::Unknown.to_string()
};
current_span.record("flow_specific_fields.status", status_str);
}
} else {
tracing::warn!("Could not serialize response to JSON to extract status");
}
}
Err(status) => {
current_span.record("error_message", status.message());
current_span.record("status_code", status.code().to_string());
}
}
tracing::info!("Golden Log Line (incoming)");
}
pub async fn grpc_logging_wrapper<T, F, Fut, R>(
request: tonic::Request<T>,
service_name: &str,
config: Arc<configs::Config>,
flow_name: FlowName,
handler: F,
) -> Result<tonic::Response<R>, tonic::Status>
where
T: serde::Serialize
+ std::fmt::Debug
+ Send
+ 'static
+ hyperswitch_masking::ErasedMaskSerialize,
F: FnOnce(RequestData<T>) -> Fut + Send,
Fut: std::future::Future<Output = Result<tonic::Response<R>, tonic::Status>> + Send,
R: serde::Serialize + std::fmt::Debug + hyperswitch_masking::ErasedMaskSerialize,
{
let current_span = tracing::Span::current();
let start_time = tokio::time::Instant::now();
let masked_request_data =
MaskedSerdeValue::from_masked_optional(request.get_ref(), "grpc_request");
let mut event_metadata_payload = None;
let mut event_headers = HashMap::new();
let grpc_response = async {
let request_data = RequestData::from_grpc_request(request, config.clone())?;
log_before_initialization(&request_data, service_name).into_grpc_status()?;
event_headers = request_data.masked_metadata.get_all_masked();
event_metadata_payload = Some(request_data.extracted_metadata.clone());
let result = handler(request_data).await;
let duration = start_time.elapsed().as_millis();
current_span.record("response_time", duration);
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 400,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_425_15
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
+ std::fmt::Debug
+ Send
+ 'static
+ hyperswitch_masking::ErasedMaskSerialize,
F: FnOnce(RequestData<T>) -> Fut + Send,
Fut: std::future::Future<Output = Result<tonic::Response<R>, tonic::Status>> + Send,
R: serde::Serialize + std::fmt::Debug + hyperswitch_masking::ErasedMaskSerialize,
{
let current_span = tracing::Span::current();
let start_time = tokio::time::Instant::now();
let masked_request_data =
MaskedSerdeValue::from_masked_optional(request.get_ref(), "grpc_request");
let mut event_metadata_payload = None;
let mut event_headers = HashMap::new();
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 425,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_425_30
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
+ std::fmt::Debug
+ Send
+ 'static
+ hyperswitch_masking::ErasedMaskSerialize,
F: FnOnce(RequestData<T>) -> Fut + Send,
Fut: std::future::Future<Output = Result<tonic::Response<R>, tonic::Status>> + Send,
R: serde::Serialize + std::fmt::Debug + hyperswitch_masking::ErasedMaskSerialize,
{
let current_span = tracing::Span::current();
let start_time = tokio::time::Instant::now();
let masked_request_data =
MaskedSerdeValue::from_masked_optional(request.get_ref(), "grpc_request");
let mut event_metadata_payload = None;
let mut event_headers = HashMap::new();
let grpc_response = async {
let request_data = RequestData::from_grpc_request(request, config.clone())?;
log_before_initialization(&request_data, service_name).into_grpc_status()?;
event_headers = request_data.masked_metadata.get_all_masked();
event_metadata_payload = Some(request_data.extracted_metadata.clone());
let result = handler(request_data).await;
let duration = start_time.elapsed().as_millis();
current_span.record("response_time", duration);
log_after_initialization(&result);
result
}
.await;
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 425,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_425_50
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
+ std::fmt::Debug
+ Send
+ 'static
+ hyperswitch_masking::ErasedMaskSerialize,
F: FnOnce(RequestData<T>) -> Fut + Send,
Fut: std::future::Future<Output = Result<tonic::Response<R>, tonic::Status>> + Send,
R: serde::Serialize + std::fmt::Debug + hyperswitch_masking::ErasedMaskSerialize,
{
let current_span = tracing::Span::current();
let start_time = tokio::time::Instant::now();
let masked_request_data =
MaskedSerdeValue::from_masked_optional(request.get_ref(), "grpc_request");
let mut event_metadata_payload = None;
let mut event_headers = HashMap::new();
let grpc_response = async {
let request_data = RequestData::from_grpc_request(request, config.clone())?;
log_before_initialization(&request_data, service_name).into_grpc_status()?;
event_headers = request_data.masked_metadata.get_all_masked();
event_metadata_payload = Some(request_data.extracted_metadata.clone());
let result = handler(request_data).await;
let duration = start_time.elapsed().as_millis();
current_span.record("response_time", duration);
log_after_initialization(&result);
result
}
.await;
create_and_emit_grpc_event(
masked_request_data,
&grpc_response,
start_time,
flow_name,
&config,
event_metadata_payload.as_ref(),
event_headers,
);
grpc_response
}
fn create_and_emit_grpc_event<R>(
masked_request_data: Option<MaskedSerdeValue>,
grpc_response: &Result<tonic::Response<R>, tonic::Status>,
start_time: tokio::time::Instant,
flow_name: FlowName,
config: &configs::Config,
metadata_payload: Option<&MetadataPayload>,
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 425,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_450_15
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
log_after_initialization(&result);
result
}
.await;
create_and_emit_grpc_event(
masked_request_data,
&grpc_response,
start_time,
flow_name,
&config,
event_metadata_payload.as_ref(),
event_headers,
);
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 450,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_450_30
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
log_after_initialization(&result);
result
}
.await;
create_and_emit_grpc_event(
masked_request_data,
&grpc_response,
start_time,
flow_name,
&config,
event_metadata_payload.as_ref(),
event_headers,
);
grpc_response
}
fn create_and_emit_grpc_event<R>(
masked_request_data: Option<MaskedSerdeValue>,
grpc_response: &Result<tonic::Response<R>, tonic::Status>,
start_time: tokio::time::Instant,
flow_name: FlowName,
config: &configs::Config,
metadata_payload: Option<&MetadataPayload>,
masked_headers: HashMap<String, String>,
) where
R: serde::Serialize,
{
let mut grpc_event = Event {
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 450,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_450_50
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
log_after_initialization(&result);
result
}
.await;
create_and_emit_grpc_event(
masked_request_data,
&grpc_response,
start_time,
flow_name,
&config,
event_metadata_payload.as_ref(),
event_headers,
);
grpc_response
}
fn create_and_emit_grpc_event<R>(
masked_request_data: Option<MaskedSerdeValue>,
grpc_response: &Result<tonic::Response<R>, tonic::Status>,
start_time: tokio::time::Instant,
flow_name: FlowName,
config: &configs::Config,
metadata_payload: Option<&MetadataPayload>,
masked_headers: HashMap<String, String>,
) where
R: serde::Serialize,
{
let mut grpc_event = Event {
request_id: metadata_payload.map_or("unknown".to_string(), |md| md.request_id.clone()),
timestamp: chrono::Utc::now().timestamp().into(),
flow_type: flow_name,
connector: metadata_payload.map_or("unknown".to_string(), |md| md.connector.to_string()),
url: None,
stage: EventStage::GrpcRequest,
latency_ms: Some(u64::try_from(start_time.elapsed().as_millis()).unwrap_or(u64::MAX)),
status_code: None,
request_data: masked_request_data,
response_data: None,
headers: masked_headers,
additional_fields: HashMap::new(),
lineage_ids: metadata_payload
.map_or_else(|| LineageIds::empty(""), |md| md.lineage_ids.clone()),
};
grpc_event
.add_reference_id(metadata_payload.and_then(|metadata| metadata.reference_id.as_deref()));
match grpc_response {
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 450,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_475_15
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
masked_headers: HashMap<String, String>,
) where
R: serde::Serialize,
{
let mut grpc_event = Event {
request_id: metadata_payload.map_or("unknown".to_string(), |md| md.request_id.clone()),
timestamp: chrono::Utc::now().timestamp().into(),
flow_type: flow_name,
connector: metadata_payload.map_or("unknown".to_string(), |md| md.connector.to_string()),
url: None,
stage: EventStage::GrpcRequest,
latency_ms: Some(u64::try_from(start_time.elapsed().as_millis()).unwrap_or(u64::MAX)),
status_code: None,
request_data: masked_request_data,
response_data: None,
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 475,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_475_30
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
masked_headers: HashMap<String, String>,
) where
R: serde::Serialize,
{
let mut grpc_event = Event {
request_id: metadata_payload.map_or("unknown".to_string(), |md| md.request_id.clone()),
timestamp: chrono::Utc::now().timestamp().into(),
flow_type: flow_name,
connector: metadata_payload.map_or("unknown".to_string(), |md| md.connector.to_string()),
url: None,
stage: EventStage::GrpcRequest,
latency_ms: Some(u64::try_from(start_time.elapsed().as_millis()).unwrap_or(u64::MAX)),
status_code: None,
request_data: masked_request_data,
response_data: None,
headers: masked_headers,
additional_fields: HashMap::new(),
lineage_ids: metadata_payload
.map_or_else(|| LineageIds::empty(""), |md| md.lineage_ids.clone()),
};
grpc_event
.add_reference_id(metadata_payload.and_then(|metadata| metadata.reference_id.as_deref()));
match grpc_response {
Ok(response) => grpc_event.set_grpc_success_response(response.get_ref()),
Err(error) => grpc_event.set_grpc_error_response(error),
}
common_utils::emit_event_with_config(grpc_event, &config.events);
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 475,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_475_50
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
masked_headers: HashMap<String, String>,
) where
R: serde::Serialize,
{
let mut grpc_event = Event {
request_id: metadata_payload.map_or("unknown".to_string(), |md| md.request_id.clone()),
timestamp: chrono::Utc::now().timestamp().into(),
flow_type: flow_name,
connector: metadata_payload.map_or("unknown".to_string(), |md| md.connector.to_string()),
url: None,
stage: EventStage::GrpcRequest,
latency_ms: Some(u64::try_from(start_time.elapsed().as_millis()).unwrap_or(u64::MAX)),
status_code: None,
request_data: masked_request_data,
response_data: None,
headers: masked_headers,
additional_fields: HashMap::new(),
lineage_ids: metadata_payload
.map_or_else(|| LineageIds::empty(""), |md| md.lineage_ids.clone()),
};
grpc_event
.add_reference_id(metadata_payload.and_then(|metadata| metadata.reference_id.as_deref()));
match grpc_response {
Ok(response) => grpc_event.set_grpc_success_response(response.get_ref()),
Err(error) => grpc_event.set_grpc_error_response(error),
}
common_utils::emit_event_with_config(grpc_event, &config.events);
}
#[macro_export]
macro_rules! implement_connector_operation {
(
fn_name: $fn_name:ident,
log_prefix: $log_prefix:literal,
request_type: $request_type:ty,
response_type: $response_type:ty,
flow_marker: $flow_marker:ty,
resource_common_data_type: $resource_common_data_type:ty,
request_data_type: $request_data_type:ty,
response_data_type: $response_data_type:ty,
request_data_constructor: $request_data_constructor:path,
common_flow_data_constructor: $common_flow_data_constructor:path,
generate_response_fn: $generate_response_fn:path,
all_keys_required: $all_keys_required:expr
) => {
async fn $fn_name(
&self,
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 475,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_500_15
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
Ok(response) => grpc_event.set_grpc_success_response(response.get_ref()),
Err(error) => grpc_event.set_grpc_error_response(error),
}
common_utils::emit_event_with_config(grpc_event, &config.events);
}
#[macro_export]
macro_rules! implement_connector_operation {
(
fn_name: $fn_name:ident,
log_prefix: $log_prefix:literal,
request_type: $request_type:ty,
response_type: $response_type:ty,
flow_marker: $flow_marker:ty,
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 500,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_500_30
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
Ok(response) => grpc_event.set_grpc_success_response(response.get_ref()),
Err(error) => grpc_event.set_grpc_error_response(error),
}
common_utils::emit_event_with_config(grpc_event, &config.events);
}
#[macro_export]
macro_rules! implement_connector_operation {
(
fn_name: $fn_name:ident,
log_prefix: $log_prefix:literal,
request_type: $request_type:ty,
response_type: $response_type:ty,
flow_marker: $flow_marker:ty,
resource_common_data_type: $resource_common_data_type:ty,
request_data_type: $request_data_type:ty,
response_data_type: $response_data_type:ty,
request_data_constructor: $request_data_constructor:path,
common_flow_data_constructor: $common_flow_data_constructor:path,
generate_response_fn: $generate_response_fn:path,
all_keys_required: $all_keys_required:expr
) => {
async fn $fn_name(
&self,
request: $crate::request::RequestData<$request_type>,
) -> Result<tonic::Response<$response_type>, tonic::Status> {
tracing::info!(concat!($log_prefix, "_FLOW: initiated"));
let service_name = request
.extensions
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 500,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_500_50
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
Ok(response) => grpc_event.set_grpc_success_response(response.get_ref()),
Err(error) => grpc_event.set_grpc_error_response(error),
}
common_utils::emit_event_with_config(grpc_event, &config.events);
}
#[macro_export]
macro_rules! implement_connector_operation {
(
fn_name: $fn_name:ident,
log_prefix: $log_prefix:literal,
request_type: $request_type:ty,
response_type: $response_type:ty,
flow_marker: $flow_marker:ty,
resource_common_data_type: $resource_common_data_type:ty,
request_data_type: $request_data_type:ty,
response_data_type: $response_data_type:ty,
request_data_constructor: $request_data_constructor:path,
common_flow_data_constructor: $common_flow_data_constructor:path,
generate_response_fn: $generate_response_fn:path,
all_keys_required: $all_keys_required:expr
) => {
async fn $fn_name(
&self,
request: $crate::request::RequestData<$request_type>,
) -> Result<tonic::Response<$response_type>, tonic::Status> {
tracing::info!(concat!($log_prefix, "_FLOW: initiated"));
let service_name = request
.extensions
.get::<String>()
.cloned()
.unwrap_or_else(|| "unknown_service".to_string());
let result = Box::pin(async{
let $crate::request::RequestData {
payload,
extracted_metadata: metadata_payload,
masked_metadata,
extensions: _ // unused in macro
} = request;
let (connector, request_id, connector_auth_details) = (metadata_payload.connector, metadata_payload.request_id, metadata_payload.connector_auth_type);
// Get connector data
let connector_data: ConnectorData<domain_types::payment_method_data::DefaultPCIHolder> = connector_integration::types::ConnectorData::get_connector_by_name(&connector);
// Get connector integration
let connector_integration: interfaces::connector_integration_v2::BoxedConnectorIntegrationV2<
'_,
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 500,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_525_15
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
request: $crate::request::RequestData<$request_type>,
) -> Result<tonic::Response<$response_type>, tonic::Status> {
tracing::info!(concat!($log_prefix, "_FLOW: initiated"));
let service_name = request
.extensions
.get::<String>()
.cloned()
.unwrap_or_else(|| "unknown_service".to_string());
let result = Box::pin(async{
let $crate::request::RequestData {
payload,
extracted_metadata: metadata_payload,
masked_metadata,
extensions: _ // unused in macro
} = request;
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 525,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_525_30
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
request: $crate::request::RequestData<$request_type>,
) -> Result<tonic::Response<$response_type>, tonic::Status> {
tracing::info!(concat!($log_prefix, "_FLOW: initiated"));
let service_name = request
.extensions
.get::<String>()
.cloned()
.unwrap_or_else(|| "unknown_service".to_string());
let result = Box::pin(async{
let $crate::request::RequestData {
payload,
extracted_metadata: metadata_payload,
masked_metadata,
extensions: _ // unused in macro
} = request;
let (connector, request_id, connector_auth_details) = (metadata_payload.connector, metadata_payload.request_id, metadata_payload.connector_auth_type);
// Get connector data
let connector_data: ConnectorData<domain_types::payment_method_data::DefaultPCIHolder> = connector_integration::types::ConnectorData::get_connector_by_name(&connector);
// Get connector integration
let connector_integration: interfaces::connector_integration_v2::BoxedConnectorIntegrationV2<
'_,
$flow_marker,
$resource_common_data_type,
$request_data_type,
$response_data_type,
> = connector_data.connector.get_connector_integration_v2();
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 525,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_525_50
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
request: $crate::request::RequestData<$request_type>,
) -> Result<tonic::Response<$response_type>, tonic::Status> {
tracing::info!(concat!($log_prefix, "_FLOW: initiated"));
let service_name = request
.extensions
.get::<String>()
.cloned()
.unwrap_or_else(|| "unknown_service".to_string());
let result = Box::pin(async{
let $crate::request::RequestData {
payload,
extracted_metadata: metadata_payload,
masked_metadata,
extensions: _ // unused in macro
} = request;
let (connector, request_id, connector_auth_details) = (metadata_payload.connector, metadata_payload.request_id, metadata_payload.connector_auth_type);
// Get connector data
let connector_data: ConnectorData<domain_types::payment_method_data::DefaultPCIHolder> = connector_integration::types::ConnectorData::get_connector_by_name(&connector);
// Get connector integration
let connector_integration: interfaces::connector_integration_v2::BoxedConnectorIntegrationV2<
'_,
$flow_marker,
$resource_common_data_type,
$request_data_type,
$response_data_type,
> = connector_data.connector.get_connector_integration_v2();
// Create connector request data
let specific_request_data = $request_data_constructor(payload.clone())
.into_grpc_status()?;
// Create common request data
let common_flow_data = $common_flow_data_constructor((payload.clone(), self.config.connectors.clone(), &masked_metadata))
.into_grpc_status()?;
// Create router data
let router_data = domain_types::router_data_v2::RouterDataV2::<
$flow_marker,
$resource_common_data_type,
$request_data_type,
$response_data_type,
> {
flow: std::marker::PhantomData,
resource_common_data: common_flow_data,
connector_auth_type: connector_auth_details,
request: specific_request_data,
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 525,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_550_15
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
$flow_marker,
$resource_common_data_type,
$request_data_type,
$response_data_type,
> = connector_data.connector.get_connector_integration_v2();
// Create connector request data
let specific_request_data = $request_data_constructor(payload.clone())
.into_grpc_status()?;
// Create common request data
let common_flow_data = $common_flow_data_constructor((payload.clone(), self.config.connectors.clone(), &masked_metadata))
.into_grpc_status()?;
// Create router data
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 550,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_550_30
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
$flow_marker,
$resource_common_data_type,
$request_data_type,
$response_data_type,
> = connector_data.connector.get_connector_integration_v2();
// Create connector request data
let specific_request_data = $request_data_constructor(payload.clone())
.into_grpc_status()?;
// Create common request data
let common_flow_data = $common_flow_data_constructor((payload.clone(), self.config.connectors.clone(), &masked_metadata))
.into_grpc_status()?;
// Create router data
let router_data = domain_types::router_data_v2::RouterDataV2::<
$flow_marker,
$resource_common_data_type,
$request_data_type,
$response_data_type,
> {
flow: std::marker::PhantomData,
resource_common_data: common_flow_data,
connector_auth_type: connector_auth_details,
request: specific_request_data,
response: Err(domain_types::router_data::ErrorResponse::default()),
};
// Execute connector processing
let flow_name = $crate::utils::flow_marker_to_flow_name::<$flow_marker>();
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 550,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_550_50
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
$flow_marker,
$resource_common_data_type,
$request_data_type,
$response_data_type,
> = connector_data.connector.get_connector_integration_v2();
// Create connector request data
let specific_request_data = $request_data_constructor(payload.clone())
.into_grpc_status()?;
// Create common request data
let common_flow_data = $common_flow_data_constructor((payload.clone(), self.config.connectors.clone(), &masked_metadata))
.into_grpc_status()?;
// Create router data
let router_data = domain_types::router_data_v2::RouterDataV2::<
$flow_marker,
$resource_common_data_type,
$request_data_type,
$response_data_type,
> {
flow: std::marker::PhantomData,
resource_common_data: common_flow_data,
connector_auth_type: connector_auth_details,
request: specific_request_data,
response: Err(domain_types::router_data::ErrorResponse::default()),
};
// Execute connector processing
let flow_name = $crate::utils::flow_marker_to_flow_name::<$flow_marker>();
let event_params = external_services::service::EventProcessingParams {
connector_name: &connector.to_string(),
service_name: &service_name,
flow_name,
event_config: &self.config.events,
request_id: &request_id,
lineage_ids: &metadata_payload.lineage_ids,
reference_id: &metadata_payload.reference_id,
shadow_mode: metadata_payload.shadow_mode,
};
let response_result = external_services::service::execute_connector_processing_step(
&self.config.proxy,
connector_integration,
router_data,
$all_keys_required,
event_params,
None,
common_enums::CallConnectorAction::Trigger,
)
.await
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 550,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_575_15
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
response: Err(domain_types::router_data::ErrorResponse::default()),
};
// Execute connector processing
let flow_name = $crate::utils::flow_marker_to_flow_name::<$flow_marker>();
let event_params = external_services::service::EventProcessingParams {
connector_name: &connector.to_string(),
service_name: &service_name,
flow_name,
event_config: &self.config.events,
request_id: &request_id,
lineage_ids: &metadata_payload.lineage_ids,
reference_id: &metadata_payload.reference_id,
shadow_mode: metadata_payload.shadow_mode,
};
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 575,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_575_30
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
response: Err(domain_types::router_data::ErrorResponse::default()),
};
// Execute connector processing
let flow_name = $crate::utils::flow_marker_to_flow_name::<$flow_marker>();
let event_params = external_services::service::EventProcessingParams {
connector_name: &connector.to_string(),
service_name: &service_name,
flow_name,
event_config: &self.config.events,
request_id: &request_id,
lineage_ids: &metadata_payload.lineage_ids,
reference_id: &metadata_payload.reference_id,
shadow_mode: metadata_payload.shadow_mode,
};
let response_result = external_services::service::execute_connector_processing_step(
&self.config.proxy,
connector_integration,
router_data,
$all_keys_required,
event_params,
None,
common_enums::CallConnectorAction::Trigger,
)
.await
.switch()
.into_grpc_status()?;
// Generate response
let final_response = $generate_response_fn(response_result)
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 575,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_575_50
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
response: Err(domain_types::router_data::ErrorResponse::default()),
};
// Execute connector processing
let flow_name = $crate::utils::flow_marker_to_flow_name::<$flow_marker>();
let event_params = external_services::service::EventProcessingParams {
connector_name: &connector.to_string(),
service_name: &service_name,
flow_name,
event_config: &self.config.events,
request_id: &request_id,
lineage_ids: &metadata_payload.lineage_ids,
reference_id: &metadata_payload.reference_id,
shadow_mode: metadata_payload.shadow_mode,
};
let response_result = external_services::service::execute_connector_processing_step(
&self.config.proxy,
connector_integration,
router_data,
$all_keys_required,
event_params,
None,
common_enums::CallConnectorAction::Trigger,
)
.await
.switch()
.into_grpc_status()?;
// Generate response
let final_response = $generate_response_fn(response_result)
.into_grpc_status()?;
Ok(tonic::Response::new(final_response))
}).await;
result
}
}
}
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 38,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 575,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_600_15
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
.switch()
.into_grpc_status()?;
// Generate response
let final_response = $generate_response_fn(response_result)
.into_grpc_status()?;
Ok(tonic::Response::new(final_response))
}).await;
result
}
}
}
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 13,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 600,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_600_30
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
.switch()
.into_grpc_status()?;
// Generate response
let final_response = $generate_response_fn(response_result)
.into_grpc_status()?;
Ok(tonic::Response::new(final_response))
}).await;
result
}
}
}
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 13,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 600,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_4018572258718428657_600_50
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/utils.rs
.switch()
.into_grpc_status()?;
// Generate response
let final_response = $generate_response_fn(response_result)
.into_grpc_status()?;
Ok(tonic::Response::new(final_response))
}).await;
result
}
}
}
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 13,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 600,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_8407789757677062419_0_15
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/logger/config.rs
//!
//! Logger-specific config.
//!
use serde::Deserialize;
/// Log config settings.
#[derive(Debug, Deserialize, Clone)]
pub struct Log {
/// Logging to a console.
pub console: LogConsole,
/// Logging to Kafka (optional).
#[serde(default)]
pub kafka: Option<LogKafka>,
}
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 0,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_8407789757677062419_0_30
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/logger/config.rs
//!
//! Logger-specific config.
//!
use serde::Deserialize;
/// Log config settings.
#[derive(Debug, Deserialize, Clone)]
pub struct Log {
/// Logging to a console.
pub console: LogConsole,
/// Logging to Kafka (optional).
#[serde(default)]
pub kafka: Option<LogKafka>,
}
/// Logging to a console.
#[derive(Debug, Deserialize, Clone)]
pub struct LogConsole {
/// Whether you want to see log in your terminal.
pub enabled: bool,
/// What you see in your terminal.
pub level: Level,
/// Log format
pub log_format: LogFormat,
/// Directive which sets the log level for one or more crates/modules.
pub filtering_directive: Option<String>,
}
/// Describes the level of verbosity of a span or event.
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 0,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_8407789757677062419_0_50
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/logger/config.rs
//!
//! Logger-specific config.
//!
use serde::Deserialize;
/// Log config settings.
#[derive(Debug, Deserialize, Clone)]
pub struct Log {
/// Logging to a console.
pub console: LogConsole,
/// Logging to Kafka (optional).
#[serde(default)]
pub kafka: Option<LogKafka>,
}
/// Logging to a console.
#[derive(Debug, Deserialize, Clone)]
pub struct LogConsole {
/// Whether you want to see log in your terminal.
pub enabled: bool,
/// What you see in your terminal.
pub level: Level,
/// Log format
pub log_format: LogFormat,
/// Directive which sets the log level for one or more crates/modules.
pub filtering_directive: Option<String>,
}
/// Describes the level of verbosity of a span or event.
#[derive(Debug, Clone, Copy)]
pub struct Level(pub(super) tracing::Level);
impl Level {
/// Returns the most verbose [`tracing::Level`]
pub fn into_level(&self) -> tracing::Level {
self.0
}
}
impl<'de> Deserialize<'de> for Level {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
use std::str::FromStr as _;
let s = String::deserialize(deserializer)?;
tracing::Level::from_str(&s)
.map(Level)
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 0,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_8407789757677062419_25_15
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/logger/config.rs
/// Directive which sets the log level for one or more crates/modules.
pub filtering_directive: Option<String>,
}
/// Describes the level of verbosity of a span or event.
#[derive(Debug, Clone, Copy)]
pub struct Level(pub(super) tracing::Level);
impl Level {
/// Returns the most verbose [`tracing::Level`]
pub fn into_level(&self) -> tracing::Level {
self.0
}
}
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 25,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_8407789757677062419_25_30
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/logger/config.rs
/// Directive which sets the log level for one or more crates/modules.
pub filtering_directive: Option<String>,
}
/// Describes the level of verbosity of a span or event.
#[derive(Debug, Clone, Copy)]
pub struct Level(pub(super) tracing::Level);
impl Level {
/// Returns the most verbose [`tracing::Level`]
pub fn into_level(&self) -> tracing::Level {
self.0
}
}
impl<'de> Deserialize<'de> for Level {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
use std::str::FromStr as _;
let s = String::deserialize(deserializer)?;
tracing::Level::from_str(&s)
.map(Level)
.map_err(serde::de::Error::custom)
}
}
/// Telemetry / tracing.
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 25,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_8407789757677062419_25_50
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/logger/config.rs
/// Directive which sets the log level for one or more crates/modules.
pub filtering_directive: Option<String>,
}
/// Describes the level of verbosity of a span or event.
#[derive(Debug, Clone, Copy)]
pub struct Level(pub(super) tracing::Level);
impl Level {
/// Returns the most verbose [`tracing::Level`]
pub fn into_level(&self) -> tracing::Level {
self.0
}
}
impl<'de> Deserialize<'de> for Level {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
use std::str::FromStr as _;
let s = String::deserialize(deserializer)?;
tracing::Level::from_str(&s)
.map(Level)
.map_err(serde::de::Error::custom)
}
}
/// Telemetry / tracing.
#[derive(Default, Debug, Deserialize, Clone, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum LogFormat {
/// Default pretty log format
Default,
/// JSON based structured logging
#[default]
Json,
}
/// Logging to Kafka.
#[derive(Debug, Deserialize, Clone)]
pub struct LogKafka {
/// Whether Kafka logging is enabled.
pub enabled: bool,
/// Minimum log level for Kafka logging.
pub level: Level,
/// Directive which sets the log level for one or more crates/modules.
pub filtering_directive: Option<String>,
/// Kafka broker addresses.
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 25,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_8407789757677062419_50_15
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/logger/config.rs
.map_err(serde::de::Error::custom)
}
}
/// Telemetry / tracing.
#[derive(Default, Debug, Deserialize, Clone, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum LogFormat {
/// Default pretty log format
Default,
/// JSON based structured logging
#[default]
Json,
}
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 50,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_8407789757677062419_50_30
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/logger/config.rs
.map_err(serde::de::Error::custom)
}
}
/// Telemetry / tracing.
#[derive(Default, Debug, Deserialize, Clone, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum LogFormat {
/// Default pretty log format
Default,
/// JSON based structured logging
#[default]
Json,
}
/// Logging to Kafka.
#[derive(Debug, Deserialize, Clone)]
pub struct LogKafka {
/// Whether Kafka logging is enabled.
pub enabled: bool,
/// Minimum log level for Kafka logging.
pub level: Level,
/// Directive which sets the log level for one or more crates/modules.
pub filtering_directive: Option<String>,
/// Kafka broker addresses.
pub brokers: Vec<String>,
/// Topic name for logs.
pub topic: String,
/// Batch size for Kafka messages (optional, defaults to Kafka default).
#[serde(default)]
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 50,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_8407789757677062419_50_50
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/logger/config.rs
.map_err(serde::de::Error::custom)
}
}
/// Telemetry / tracing.
#[derive(Default, Debug, Deserialize, Clone, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum LogFormat {
/// Default pretty log format
Default,
/// JSON based structured logging
#[default]
Json,
}
/// Logging to Kafka.
#[derive(Debug, Deserialize, Clone)]
pub struct LogKafka {
/// Whether Kafka logging is enabled.
pub enabled: bool,
/// Minimum log level for Kafka logging.
pub level: Level,
/// Directive which sets the log level for one or more crates/modules.
pub filtering_directive: Option<String>,
/// Kafka broker addresses.
pub brokers: Vec<String>,
/// Topic name for logs.
pub topic: String,
/// Batch size for Kafka messages (optional, defaults to Kafka default).
#[serde(default)]
pub batch_size: Option<usize>,
/// Flush interval in milliseconds (optional, defaults to Kafka default).
#[serde(default)]
pub flush_interval_ms: Option<u64>,
/// Buffer limit for Kafka messages (optional, defaults to Kafka default).
#[serde(default)]
pub buffer_limit: Option<usize>,
}
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 38,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 50,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_8407789757677062419_75_15
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/logger/config.rs
pub brokers: Vec<String>,
/// Topic name for logs.
pub topic: String,
/// Batch size for Kafka messages (optional, defaults to Kafka default).
#[serde(default)]
pub batch_size: Option<usize>,
/// Flush interval in milliseconds (optional, defaults to Kafka default).
#[serde(default)]
pub flush_interval_ms: Option<u64>,
/// Buffer limit for Kafka messages (optional, defaults to Kafka default).
#[serde(default)]
pub buffer_limit: Option<usize>,
}
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 13,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 75,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_8407789757677062419_75_30
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/logger/config.rs
pub brokers: Vec<String>,
/// Topic name for logs.
pub topic: String,
/// Batch size for Kafka messages (optional, defaults to Kafka default).
#[serde(default)]
pub batch_size: Option<usize>,
/// Flush interval in milliseconds (optional, defaults to Kafka default).
#[serde(default)]
pub flush_interval_ms: Option<u64>,
/// Buffer limit for Kafka messages (optional, defaults to Kafka default).
#[serde(default)]
pub buffer_limit: Option<usize>,
}
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 13,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 75,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_8407789757677062419_75_50
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/logger/config.rs
pub brokers: Vec<String>,
/// Topic name for logs.
pub topic: String,
/// Batch size for Kafka messages (optional, defaults to Kafka default).
#[serde(default)]
pub batch_size: Option<usize>,
/// Flush interval in milliseconds (optional, defaults to Kafka default).
#[serde(default)]
pub flush_interval_ms: Option<u64>,
/// Buffer limit for Kafka messages (optional, defaults to Kafka default).
#[serde(default)]
pub buffer_limit: Option<usize>,
}
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 13,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 75,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_-8301123723402502079_0_15
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/logger/env.rs
#[macro_export]
macro_rules! service_name {
() => {
env!("CARGO_BIN_NAME")
};
}
#[macro_export]
macro_rules! git_describe {
() => {
env!("VERGEN_GIT_DESCRIBE")
};
}
#[macro_export]
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 0,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_-8301123723402502079_0_30
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/logger/env.rs
#[macro_export]
macro_rules! service_name {
() => {
env!("CARGO_BIN_NAME")
};
}
#[macro_export]
macro_rules! git_describe {
() => {
env!("VERGEN_GIT_DESCRIBE")
};
}
#[macro_export]
macro_rules! version {
() => {
concat!(
env!("VERGEN_GIT_DESCRIBE"),
"-",
env!("VERGEN_GIT_SHA"),
"-",
env!("VERGEN_GIT_COMMIT_TIMESTAMP"),
)
};
}
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 26,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 0,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_-8301123723402502079_0_50
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/logger/env.rs
#[macro_export]
macro_rules! service_name {
() => {
env!("CARGO_BIN_NAME")
};
}
#[macro_export]
macro_rules! git_describe {
() => {
env!("VERGEN_GIT_DESCRIBE")
};
}
#[macro_export]
macro_rules! version {
() => {
concat!(
env!("VERGEN_GIT_DESCRIBE"),
"-",
env!("VERGEN_GIT_SHA"),
"-",
env!("VERGEN_GIT_COMMIT_TIMESTAMP"),
)
};
}
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 26,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 0,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_-1230957448226898650_0_15
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/logger/formatter.rs
//!
//! Formatting [layer](https://docs.rs/tracing-subscriber/0.3.15/tracing_subscriber/layer/trait.Layer.html) for Router.
//!
use std::{
collections::{HashMap, HashSet},
fmt,
io::Write,
};
use common_utils::consts::{
LOG_FILE as FILE, LOG_FN as FN, LOG_FULL_NAME as FULL_NAME, LOG_HOSTNAME as HOSTNAME,
LOG_LEVEL as LEVEL, LOG_LINE as LINE, LOG_MESSAGE as MESSAGE, LOG_PID as PID,
LOG_SERVICE as SERVICE, LOG_TARGET as TARGET, LOG_TIME as TIME,
};
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 0,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_-1230957448226898650_0_30
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/logger/formatter.rs
//!
//! Formatting [layer](https://docs.rs/tracing-subscriber/0.3.15/tracing_subscriber/layer/trait.Layer.html) for Router.
//!
use std::{
collections::{HashMap, HashSet},
fmt,
io::Write,
};
use common_utils::consts::{
LOG_FILE as FILE, LOG_FN as FN, LOG_FULL_NAME as FULL_NAME, LOG_HOSTNAME as HOSTNAME,
LOG_LEVEL as LEVEL, LOG_LINE as LINE, LOG_MESSAGE as MESSAGE, LOG_PID as PID,
LOG_SERVICE as SERVICE, LOG_TARGET as TARGET, LOG_TIME as TIME,
};
use once_cell::sync::Lazy;
use serde::ser::{SerializeMap, Serializer};
use serde_json::Value;
use super::storage::Storage;
use time::format_description::well_known::Iso8601;
use tracing::{Event, Metadata, Subscriber};
use tracing_subscriber::{
fmt::MakeWriter,
layer::Context,
registry::{LookupSpan, SpanRef},
Layer,
};
// TODO: Documentation coverage for this crate
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 0,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_-1230957448226898650_0_50
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/logger/formatter.rs
//!
//! Formatting [layer](https://docs.rs/tracing-subscriber/0.3.15/tracing_subscriber/layer/trait.Layer.html) for Router.
//!
use std::{
collections::{HashMap, HashSet},
fmt,
io::Write,
};
use common_utils::consts::{
LOG_FILE as FILE, LOG_FN as FN, LOG_FULL_NAME as FULL_NAME, LOG_HOSTNAME as HOSTNAME,
LOG_LEVEL as LEVEL, LOG_LINE as LINE, LOG_MESSAGE as MESSAGE, LOG_PID as PID,
LOG_SERVICE as SERVICE, LOG_TARGET as TARGET, LOG_TIME as TIME,
};
use once_cell::sync::Lazy;
use serde::ser::{SerializeMap, Serializer};
use serde_json::Value;
use super::storage::Storage;
use time::format_description::well_known::Iso8601;
use tracing::{Event, Metadata, Subscriber};
use tracing_subscriber::{
fmt::MakeWriter,
layer::Context,
registry::{LookupSpan, SpanRef},
Layer,
};
// TODO: Documentation coverage for this crate
// Implicit keys
/// Set of predefined implicit keys.
pub static IMPLICIT_KEYS: Lazy<rustc_hash::FxHashSet<&str>> = Lazy::new(|| {
let mut set = rustc_hash::FxHashSet::default();
set.insert(HOSTNAME);
set.insert(PID);
set.insert(LEVEL);
set.insert(TARGET);
set.insert(SERVICE);
set.insert(LINE);
set.insert(FILE);
set.insert(FN);
set.insert(FULL_NAME);
set.insert(TIME);
set
});
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 0,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_-1230957448226898650_25_15
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/logger/formatter.rs
registry::{LookupSpan, SpanRef},
Layer,
};
// TODO: Documentation coverage for this crate
// Implicit keys
/// Set of predefined implicit keys.
pub static IMPLICIT_KEYS: Lazy<rustc_hash::FxHashSet<&str>> = Lazy::new(|| {
let mut set = rustc_hash::FxHashSet::default();
set.insert(HOSTNAME);
set.insert(PID);
set.insert(LEVEL);
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 25,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_-1230957448226898650_25_30
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/logger/formatter.rs
registry::{LookupSpan, SpanRef},
Layer,
};
// TODO: Documentation coverage for this crate
// Implicit keys
/// Set of predefined implicit keys.
pub static IMPLICIT_KEYS: Lazy<rustc_hash::FxHashSet<&str>> = Lazy::new(|| {
let mut set = rustc_hash::FxHashSet::default();
set.insert(HOSTNAME);
set.insert(PID);
set.insert(LEVEL);
set.insert(TARGET);
set.insert(SERVICE);
set.insert(LINE);
set.insert(FILE);
set.insert(FN);
set.insert(FULL_NAME);
set.insert(TIME);
set
});
/// Describe type of record: entering a span, exiting a span, an event.
#[derive(Clone, Debug)]
pub enum RecordType {
/// Entering a span.
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 25,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_-1230957448226898650_25_50
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/logger/formatter.rs
registry::{LookupSpan, SpanRef},
Layer,
};
// TODO: Documentation coverage for this crate
// Implicit keys
/// Set of predefined implicit keys.
pub static IMPLICIT_KEYS: Lazy<rustc_hash::FxHashSet<&str>> = Lazy::new(|| {
let mut set = rustc_hash::FxHashSet::default();
set.insert(HOSTNAME);
set.insert(PID);
set.insert(LEVEL);
set.insert(TARGET);
set.insert(SERVICE);
set.insert(LINE);
set.insert(FILE);
set.insert(FN);
set.insert(FULL_NAME);
set.insert(TIME);
set
});
/// Describe type of record: entering a span, exiting a span, an event.
#[derive(Clone, Debug)]
pub enum RecordType {
/// Entering a span.
EnterSpan,
/// Exiting a span.
ExitSpan,
/// Event.
Event,
}
impl fmt::Display for RecordType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let repr = match self {
Self::EnterSpan => "START",
Self::ExitSpan => "END",
Self::Event => "EVENT",
};
write!(f, "{repr}")
}
}
///
/// Format log records.
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 25,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_-1230957448226898650_50_15
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/logger/formatter.rs
/// Describe type of record: entering a span, exiting a span, an event.
#[derive(Clone, Debug)]
pub enum RecordType {
/// Entering a span.
EnterSpan,
/// Exiting a span.
ExitSpan,
/// Event.
Event,
}
impl fmt::Display for RecordType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let repr = match self {
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 50,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_-1230957448226898650_50_30
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/logger/formatter.rs
/// Describe type of record: entering a span, exiting a span, an event.
#[derive(Clone, Debug)]
pub enum RecordType {
/// Entering a span.
EnterSpan,
/// Exiting a span.
ExitSpan,
/// Event.
Event,
}
impl fmt::Display for RecordType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let repr = match self {
Self::EnterSpan => "START",
Self::ExitSpan => "END",
Self::Event => "EVENT",
};
write!(f, "{repr}")
}
}
///
/// Format log records.
/// `FormattingLayer` relies on the `tracing_bunyan_formatter::JsonStorageLayer` which is storage of entries.
///
#[derive(Debug)]
pub struct FormattingLayer<W>
where
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 50,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_-1230957448226898650_50_50
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/logger/formatter.rs
/// Describe type of record: entering a span, exiting a span, an event.
#[derive(Clone, Debug)]
pub enum RecordType {
/// Entering a span.
EnterSpan,
/// Exiting a span.
ExitSpan,
/// Event.
Event,
}
impl fmt::Display for RecordType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let repr = match self {
Self::EnterSpan => "START",
Self::ExitSpan => "END",
Self::Event => "EVENT",
};
write!(f, "{repr}")
}
}
///
/// Format log records.
/// `FormattingLayer` relies on the `tracing_bunyan_formatter::JsonStorageLayer` which is storage of entries.
///
#[derive(Debug)]
pub struct FormattingLayer<W>
where
W: for<'a> MakeWriter<'a> + 'static,
{
dst_writer: W,
pid: u32,
hostname: String,
service: String,
default_fields: HashMap<String, Value>,
}
impl<W> FormattingLayer<W>
where
W: for<'a> MakeWriter<'a> + 'static,
{
///
/// Constructor of `FormattingLayer`.
///
/// A `name` will be attached to all records during formatting.
/// A `dst_writer` to forward all records.
///
/// ## Example
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 50,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_-1230957448226898650_75_15
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/logger/formatter.rs
/// `FormattingLayer` relies on the `tracing_bunyan_formatter::JsonStorageLayer` which is storage of entries.
///
#[derive(Debug)]
pub struct FormattingLayer<W>
where
W: for<'a> MakeWriter<'a> + 'static,
{
dst_writer: W,
pid: u32,
hostname: String,
service: String,
default_fields: HashMap<String, Value>,
}
impl<W> FormattingLayer<W>
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 75,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_-1230957448226898650_75_30
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/logger/formatter.rs
/// `FormattingLayer` relies on the `tracing_bunyan_formatter::JsonStorageLayer` which is storage of entries.
///
#[derive(Debug)]
pub struct FormattingLayer<W>
where
W: for<'a> MakeWriter<'a> + 'static,
{
dst_writer: W,
pid: u32,
hostname: String,
service: String,
default_fields: HashMap<String, Value>,
}
impl<W> FormattingLayer<W>
where
W: for<'a> MakeWriter<'a> + 'static,
{
///
/// Constructor of `FormattingLayer`.
///
/// A `name` will be attached to all records during formatting.
/// A `dst_writer` to forward all records.
///
/// ## Example
/// ```rust,ignore
/// let formatting_layer = router_env::FormattingLayer::new(env::service_name!(),std::io::stdout);
/// ```
///
pub fn new(service: &str, dst_writer: W) -> Self {
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 75,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_-1230957448226898650_75_50
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/logger/formatter.rs
/// `FormattingLayer` relies on the `tracing_bunyan_formatter::JsonStorageLayer` which is storage of entries.
///
#[derive(Debug)]
pub struct FormattingLayer<W>
where
W: for<'a> MakeWriter<'a> + 'static,
{
dst_writer: W,
pid: u32,
hostname: String,
service: String,
default_fields: HashMap<String, Value>,
}
impl<W> FormattingLayer<W>
where
W: for<'a> MakeWriter<'a> + 'static,
{
///
/// Constructor of `FormattingLayer`.
///
/// A `name` will be attached to all records during formatting.
/// A `dst_writer` to forward all records.
///
/// ## Example
/// ```rust,ignore
/// let formatting_layer = router_env::FormattingLayer::new(env::service_name!(),std::io::stdout);
/// ```
///
pub fn new(service: &str, dst_writer: W) -> Self {
Self::new_with_implicit_entries(service, dst_writer, HashMap::new())
}
/// Construct of `FormattingLayer with implicit default entries.
pub fn new_with_implicit_entries(
service: &str,
dst_writer: W,
mut default_fields: HashMap<String, Value>,
) -> Self {
let pid = std::process::id();
let hostname = gethostname::gethostname().to_string_lossy().into_owned();
let service = service.to_string();
default_fields.retain(|key, value| {
if !IMPLICIT_KEYS.contains(key.as_str()) {
true
} else {
#[allow(clippy::print_stderr)]
{
eprintln!(
"Attempting to log a reserved entry. It won't be added to the logs. key: {:?}, value: {:?}",
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 75,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_-1230957448226898650_100_15
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/logger/formatter.rs
/// ```rust,ignore
/// let formatting_layer = router_env::FormattingLayer::new(env::service_name!(),std::io::stdout);
/// ```
///
pub fn new(service: &str, dst_writer: W) -> Self {
Self::new_with_implicit_entries(service, dst_writer, HashMap::new())
}
/// Construct of `FormattingLayer with implicit default entries.
pub fn new_with_implicit_entries(
service: &str,
dst_writer: W,
mut default_fields: HashMap<String, Value>,
) -> Self {
let pid = std::process::id();
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 100,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_-1230957448226898650_100_30
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/logger/formatter.rs
/// ```rust,ignore
/// let formatting_layer = router_env::FormattingLayer::new(env::service_name!(),std::io::stdout);
/// ```
///
pub fn new(service: &str, dst_writer: W) -> Self {
Self::new_with_implicit_entries(service, dst_writer, HashMap::new())
}
/// Construct of `FormattingLayer with implicit default entries.
pub fn new_with_implicit_entries(
service: &str,
dst_writer: W,
mut default_fields: HashMap<String, Value>,
) -> Self {
let pid = std::process::id();
let hostname = gethostname::gethostname().to_string_lossy().into_owned();
let service = service.to_string();
default_fields.retain(|key, value| {
if !IMPLICIT_KEYS.contains(key.as_str()) {
true
} else {
#[allow(clippy::print_stderr)]
{
eprintln!(
"Attempting to log a reserved entry. It won't be added to the logs. key: {:?}, value: {:?}",
key, value);
}
false
}
});
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 100,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_-1230957448226898650_100_50
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/logger/formatter.rs
/// ```rust,ignore
/// let formatting_layer = router_env::FormattingLayer::new(env::service_name!(),std::io::stdout);
/// ```
///
pub fn new(service: &str, dst_writer: W) -> Self {
Self::new_with_implicit_entries(service, dst_writer, HashMap::new())
}
/// Construct of `FormattingLayer with implicit default entries.
pub fn new_with_implicit_entries(
service: &str,
dst_writer: W,
mut default_fields: HashMap<String, Value>,
) -> Self {
let pid = std::process::id();
let hostname = gethostname::gethostname().to_string_lossy().into_owned();
let service = service.to_string();
default_fields.retain(|key, value| {
if !IMPLICIT_KEYS.contains(key.as_str()) {
true
} else {
#[allow(clippy::print_stderr)]
{
eprintln!(
"Attempting to log a reserved entry. It won't be added to the logs. key: {:?}, value: {:?}",
key, value);
}
false
}
});
Self {
dst_writer,
pid,
hostname,
service,
default_fields,
}
}
/// Serialize common for both span and event entries.
fn common_serialize<S>(
&self,
map_serializer: &mut impl SerializeMap<Error = serde_json::Error>,
metadata: &Metadata<'_>,
span: Option<&SpanRef<'_, S>>,
storage: &Storage<'_>,
name: &str,
) -> Result<(), std::io::Error>
where
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 100,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_-1230957448226898650_125_15
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/logger/formatter.rs
key, value);
}
false
}
});
Self {
dst_writer,
pid,
hostname,
service,
default_fields,
}
}
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 125,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_-1230957448226898650_125_30
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/logger/formatter.rs
key, value);
}
false
}
});
Self {
dst_writer,
pid,
hostname,
service,
default_fields,
}
}
/// Serialize common for both span and event entries.
fn common_serialize<S>(
&self,
map_serializer: &mut impl SerializeMap<Error = serde_json::Error>,
metadata: &Metadata<'_>,
span: Option<&SpanRef<'_, S>>,
storage: &Storage<'_>,
name: &str,
) -> Result<(), std::io::Error>
where
S: Subscriber + for<'a> LookupSpan<'a>,
{
let is_extra = |s: &str| !IMPLICIT_KEYS.contains(s);
map_serializer.serialize_entry(HOSTNAME, &self.hostname)?;
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 30,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 125,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_-1230957448226898650_125_50
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/logger/formatter.rs
key, value);
}
false
}
});
Self {
dst_writer,
pid,
hostname,
service,
default_fields,
}
}
/// Serialize common for both span and event entries.
fn common_serialize<S>(
&self,
map_serializer: &mut impl SerializeMap<Error = serde_json::Error>,
metadata: &Metadata<'_>,
span: Option<&SpanRef<'_, S>>,
storage: &Storage<'_>,
name: &str,
) -> Result<(), std::io::Error>
where
S: Subscriber + for<'a> LookupSpan<'a>,
{
let is_extra = |s: &str| !IMPLICIT_KEYS.contains(s);
map_serializer.serialize_entry(HOSTNAME, &self.hostname)?;
map_serializer.serialize_entry(PID, &self.pid)?;
map_serializer.serialize_entry(LEVEL, &format_args!("{}", metadata.level()))?;
map_serializer.serialize_entry(TARGET, metadata.target())?;
map_serializer.serialize_entry(SERVICE, &self.service)?;
map_serializer.serialize_entry(LINE, &metadata.line())?;
map_serializer.serialize_entry(FILE, &metadata.file())?;
map_serializer.serialize_entry(FN, name)?;
map_serializer
.serialize_entry(FULL_NAME, &format_args!("{}::{}", metadata.target(), name))?;
if let Ok(time) = &time::OffsetDateTime::now_utc().format(&Iso8601::DEFAULT) {
map_serializer.serialize_entry(TIME, time)?;
}
// Write down implicit default entries.
for (key, value) in self.default_fields.iter() {
map_serializer.serialize_entry(key, value)?;
}
let mut explicit_entries_set: HashSet<&str> = HashSet::default();
// Write down explicit event's entries.
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 50,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 125,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
connector-service_snippet_-1230957448226898650_150_15
|
clm
|
snippet
|
// connector-service/backend/grpc-server/src/logger/formatter.rs
S: Subscriber + for<'a> LookupSpan<'a>,
{
let is_extra = |s: &str| !IMPLICIT_KEYS.contains(s);
map_serializer.serialize_entry(HOSTNAME, &self.hostname)?;
map_serializer.serialize_entry(PID, &self.pid)?;
map_serializer.serialize_entry(LEVEL, &format_args!("{}", metadata.level()))?;
map_serializer.serialize_entry(TARGET, metadata.target())?;
map_serializer.serialize_entry(SERVICE, &self.service)?;
map_serializer.serialize_entry(LINE, &metadata.line())?;
map_serializer.serialize_entry(FILE, &metadata.file())?;
map_serializer.serialize_entry(FN, name)?;
map_serializer
.serialize_entry(FULL_NAME, &format_args!("{}::{}", metadata.target(), name))?;
if let Ok(time) = &time::OffsetDateTime::now_utc().format(&Iso8601::DEFAULT) {
|
{
"chunk": null,
"crate": "grpc-server",
"enum_name": null,
"file_size": null,
"for_type": null,
"function_name": null,
"is_async": null,
"is_pub": null,
"lines": 15,
"method_name": null,
"num_enums": null,
"num_items": null,
"num_structs": null,
"repo": "connector-service",
"start_line": 150,
"struct_name": null,
"total_crates": null,
"trait_name": null
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.