@@ -50,22 +50,22 @@ const (
5050 maxRecordedSpansPerTrace = 1000
5151 // maxRecordedBytesPerSpan limits the size of unstructured logs in a span.
5252 maxLogBytesPerSpan = 256 * (1 << 10 ) // 256 KiB
53- // maxStructuredBytesPerSpan limits the size of structured logs in a span.
53+ // defaultMaxStructuredBytesPerSpan limits the size of structured logs in a span.
5454 // This limit applies to records directly logged into the span; it does not
5555 // apply to records in child span (including structured records copied from
5656 // the child into the parent when the child is dropped because of the number
5757 // of spans limit).
5858 // See also maxStructuredBytesPerTrace.
59- maxStructuredBytesPerSpan = 10 * (1 << 10 ) // 10 KiB
60- // maxStructuredBytesPerTrace limits the total size of structured logs in a
59+ defaultMaxStructuredBytesPerSpan = 10 * (1 << 10 ) // 10 KiB
60+ // defaultMaxStructuredBytesPerTrace limits the total size of structured logs in a
6161 // trace recording, across all spans. This limit is enforced at the time when
6262 // a span is finished and its recording is copied to the parent, and at the
6363 // time when an open span's recording is collected - which calls into all its
6464 // open children. Thus, if there are multiple open spans that are part of the
6565 // same trace, each one of them can temporarily have up to
66- // maxStructuredBytesPerTrace worth of messages under it. Each open span is
67- // also subject to the maxStructuredBytesPerSpan limit.
68- maxStructuredBytesPerTrace = 1 << 20 // 1 MiB
66+ // defaultMaxStructuredBytesPerTrace worth of messages under it. Each open span is
67+ // also subject to the defaultMaxStructuredBytesPerSpan limit.
68+ defaultMaxStructuredBytesPerTrace = 1 << 20 // 1 MiB
6969
7070 // maxSpanRegistrySize limits the number of local root spans tracked in
7171 // a Tracer's registry.
@@ -189,6 +189,18 @@ var periodicSnapshotInterval = settings.RegisterDurationSetting(
189189 0 ,
190190 settings .WithPublic )
191191
192+ var structuredBytesLimit = settings .RegisterByteSizeSetting (
193+ settings .ApplicationLevel ,
194+ "trace.structured_bytes_per_trace.max" ,
195+ "maximum size of structured log entries per trace recording" ,
196+ defaultMaxStructuredBytesPerTrace )
197+
198+ var structuredBytesPerSpanLimit = settings .RegisterByteSizeSetting (
199+ settings .ApplicationLevel ,
200+ "trace.structured_bytes_per_span.max" ,
201+ "maximum size of structured log entries per span" ,
202+ defaultMaxStructuredBytesPerSpan )
203+
192204// panicOnUseAfterFinish, if set, causes use of a span after Finish() to panic
193205// if detected.
194206var panicOnUseAfterFinish = buildutil .CrdbTestBuild ||
@@ -368,6 +380,16 @@ type Tracer struct {
368380
369381 testing TracerTestingKnobs
370382
383+ // maxStructuredBytesPerTrace limits the total size of structured logs in a
384+ // trace recording. This value is configurable via the
385+ // trace.structured_bytes_per_trace.max cluster setting.
386+ _maxStructuredBytesPerTrace int64 // accessed atomically
387+
388+ // maxStructuredBytesPerSpan limits the size of structured logs in each span.
389+ // This value is configurable via the trace.structured_bytes_per_span.max
390+ // cluster setting.
391+ _maxStructuredBytesPerSpan int64 // accessed atomically
392+
371393 // stack is populated in NewTracer and is printed in assertions related to
372394 // mixing tracers.
373395 stack debugutil.SafeStack
@@ -588,6 +610,30 @@ func (t *Tracer) SetActiveSpansRegistryEnabled(to bool) {
588610 atomic .StoreInt32 (& t ._activeSpansRegistryEnabled , n )
589611}
590612
613+ // SetMaxStructuredBytesPerTrace sets the maximum size of structured logs per
614+ // trace recording.
615+ func (t * Tracer ) SetMaxStructuredBytesPerTrace (limit int64 ) {
616+ atomic .StoreInt64 (& t ._maxStructuredBytesPerTrace , limit )
617+ }
618+
619+ // MaxStructuredBytesPerTrace returns the maximum size of structured logs per
620+ // trace recording.
621+ func (t * Tracer ) MaxStructuredBytesPerTrace () int64 {
622+ return atomic .LoadInt64 (& t ._maxStructuredBytesPerTrace )
623+ }
624+
625+ // SetMaxStructuredBytesPerSpan sets the maximum size of structured logs per
626+ // span.
627+ func (t * Tracer ) SetMaxStructuredBytesPerSpan (limit int64 ) {
628+ atomic .StoreInt64 (& t ._maxStructuredBytesPerSpan , limit )
629+ }
630+
631+ // MaxStructuredBytesPerSpan returns the maximum size of structured logs per
632+ // span.
633+ func (t * Tracer ) MaxStructuredBytesPerSpan () int64 {
634+ return atomic .LoadInt64 (& t ._maxStructuredBytesPerSpan )
635+ }
636+
591637// ActiveSpansRegistryEnabled returns true if this tracer is configured
592638// to register spans with the activeSpansRegistry
593639func (t * Tracer ) ActiveSpansRegistryEnabled () bool {
@@ -606,8 +652,10 @@ func NewTracer() *Tracer {
606652 }
607653
608654 t := & Tracer {
609- stack : debugutil .Stack (),
610- activeSpansRegistry : makeSpanRegistry (),
655+ stack : debugutil .Stack (),
656+ activeSpansRegistry : makeSpanRegistry (),
657+ _maxStructuredBytesPerTrace : defaultMaxStructuredBytesPerTrace ,
658+ _maxStructuredBytesPerSpan : defaultMaxStructuredBytesPerSpan ,
611659 // These might be overridden in NewTracerWithOpt.
612660 panicOnUseAfterFinish : panicOnUseAfterFinish ,
613661 debugUseAfterFinish : debugUseAfterFinish ,
@@ -785,6 +833,11 @@ func (t *Tracer) configure(ctx context.Context, sv *settings.Values, tracingDefa
785833 otlpCollectorAddr := openTelemetryCollector .Get (sv )
786834 zipkinAddr := ZipkinCollector .Get (sv )
787835 enableRedactable := enableTraceRedactable .Get (sv )
836+ structuredBytesLimitVal := structuredBytesLimit .Get (sv )
837+ structuredBytesPerSpanLimitVal := structuredBytesPerSpanLimit .Get (sv )
838+
839+ t .SetMaxStructuredBytesPerTrace (structuredBytesLimitVal )
840+ t .SetMaxStructuredBytesPerSpan (structuredBytesPerSpanLimitVal )
788841
789842 switch tracingDefault {
790843 case TracingModeFromEnv :
@@ -872,6 +925,8 @@ func (t *Tracer) configure(ctx context.Context, sv *settings.Values, tracingDefa
872925 openTelemetryCollector .SetOnChange (sv , reconfigure )
873926 ZipkinCollector .SetOnChange (sv , reconfigure )
874927 enableTraceRedactable .SetOnChange (sv , reconfigure )
928+ structuredBytesLimit .SetOnChange (sv , reconfigure )
929+ structuredBytesPerSpanLimit .SetOnChange (sv , reconfigure )
875930}
876931
877932func createOTLPSpanProcessor (
0 commit comments