@@ -257,7 +257,7 @@ static void destroy_opentelemetry_context(
257257 struct cmt_opentelemetry_context * context );
258258
259259static struct cmt_opentelemetry_context * initialize_opentelemetry_context (
260- struct cmt * cmt );
260+ struct cmt * cmt , struct cmt_opentelemetry_context_cutoff_opts * opts );
261261
262262static inline Opentelemetry__Proto__Common__V1__AnyValue * cfl_variant_to_otlp_any_value (struct cfl_variant * value );
263263static inline Opentelemetry__Proto__Common__V1__KeyValue * cfl_variant_kvpair_to_otlp_kvpair (struct cfl_kvpair * input_pair );
@@ -2138,7 +2138,7 @@ static Opentelemetry__Proto__Resource__V1__Resource *
21382138}
21392139
21402140static struct cmt_opentelemetry_context * initialize_opentelemetry_context (
2141- struct cmt * cmt )
2141+ struct cmt * cmt , struct cmt_opentelemetry_context_cutoff_opts * opts )
21422142{
21432143 struct cfl_kvlist * resource_metrics_root ;
21442144 struct cfl_kvlist * scope_metrics_root ;
@@ -2166,6 +2166,8 @@ static struct cmt_opentelemetry_context *initialize_opentelemetry_context(
21662166 memset (context , 0 , sizeof (struct cmt_opentelemetry_context ));
21672167
21682168 context -> cmt = cmt ;
2169+ context -> use_cutoff = opts -> use_cutoff ;
2170+ context -> cutoff_threshold = opts -> cutoff_threshold ;
21692171
21702172 resource = initialize_resource (resource_root , & result );
21712173
@@ -2447,8 +2449,9 @@ int pack_basic_type(struct cmt_opentelemetry_context *context,
24472449 & map -> metric ,
24482450 sample_index ++ );
24492451
2450- if (check_staled_timestamp (& map -> metric , now ,
2451- CMT_ENCODE_OPENTELEMETRY_CUTOFF_THRESHOLD )) {
2452+ if (context -> use_cutoff == CMT_TRUE &&
2453+ check_staled_timestamp (& map -> metric , now ,
2454+ context -> cutoff_threshold )) {
24522455 destroy_metric (metric );
24532456
24542457 /* Skip processing metrics which are staled over the threshold */
@@ -2465,8 +2468,9 @@ int pack_basic_type(struct cmt_opentelemetry_context *context,
24652468 cfl_list_foreach (head , & map -> metrics ) {
24662469 sample = cfl_list_entry (head , struct cmt_metric , _head );
24672470
2468- if (check_staled_timestamp (& map -> metric , now ,
2469- CMT_ENCODE_OPENTELEMETRY_CUTOFF_THRESHOLD )) {
2471+ if (context -> use_cutoff == CMT_TRUE &&
2472+ check_staled_timestamp (& map -> metric , now ,
2473+ context -> cutoff_threshold )) {
24702474 destroy_metric (metric );
24712475
24722476 /* Skip processing metrics which are staled over the threshold */
@@ -2527,7 +2531,8 @@ static cfl_sds_t render_opentelemetry_context_to_sds(
25272531 return result_buffer ;
25282532}
25292533
2530- cfl_sds_t cmt_encode_opentelemetry_create (struct cmt * cmt )
2534+ cfl_sds_t cmt_encode_opentelemetry_create_with_cutoff_opts (struct cmt * cmt ,
2535+ struct cmt_opentelemetry_context_cutoff_opts * opts )
25312536{
25322537 size_t metric_index ;
25332538 struct cmt_opentelemetry_context * context ;
@@ -2543,7 +2548,7 @@ cfl_sds_t cmt_encode_opentelemetry_create(struct cmt *cmt)
25432548 buf = NULL ;
25442549 result = 0 ;
25452550
2546- context = initialize_opentelemetry_context (cmt );
2551+ context = initialize_opentelemetry_context (cmt , opts );
25472552
25482553 if (context == NULL ) {
25492554 return NULL ;
@@ -2638,6 +2643,24 @@ cfl_sds_t cmt_encode_opentelemetry_create(struct cmt *cmt)
26382643 return buf ;
26392644}
26402645
2646+ cfl_sds_t cmt_encode_opentelemetry_create_with_cutoff (struct cmt * cmt , int use_cutoff )
2647+ {
2648+ struct cmt_opentelemetry_context_cutoff_opts opts ;
2649+ opts .use_cutoff = use_cutoff ;
2650+ opts .cutoff_threshold = CMT_ENCODE_OPENTELEMETRY_CUTOFF_THRESHOLD ;
2651+
2652+ return cmt_encode_opentelemetry_create_with_cutoff_opts (cmt , & opts );
2653+ }
2654+
2655+ cfl_sds_t cmt_encode_opentelemetry_create (struct cmt * cmt )
2656+ {
2657+ struct cmt_opentelemetry_context_cutoff_opts opts ;
2658+ opts .use_cutoff = CMT_FALSE ;
2659+ opts .cutoff_threshold = CMT_ENCODE_OPENTELEMETRY_CUTOFF_DISABLED ;
2660+
2661+ return cmt_encode_opentelemetry_create_with_cutoff_opts (cmt , & opts );
2662+ }
2663+
26412664void cmt_encode_opentelemetry_destroy (cfl_sds_t text )
26422665{
26432666 cfl_sds_destroy (text );
0 commit comments