Skip to content

Commit 7730145

Browse files
committed
populate all optional fields in random logs
1 parent 14cf56c commit 7730145

3 files changed

Lines changed: 11 additions & 43 deletions

File tree

scripts/generate_typescript_structs.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,9 @@ def self.generate_source_ts(payload)
343343
if ts_source_const == "Source"
344344
lines << " source: (gen.sample(Object.values(Source) as unknown as Source[])),"
345345
end
346-
# Required fields get random defaults with precedence:
346+
# Populate defaults for all fields with precedence:
347347
# schema sample_type > SampleByLogField > base type fallback
348348
(payload.base_fields + event_only).each do |f|
349-
next unless f.required
350349
ts = ts_type(f.sorbet_type)
351350
base = case ts
352351
when "string" then "'sample'"

site/app/docs/logging/page.tsx

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -77,32 +77,6 @@ logger.formatter = config.log_formatter
7777
config.logger = ActiveSupport::TaggedLogging.new(logger)`}
7878
</CodeBlock>
7979

80-
<HeadingWithAnchor id="dotenv-rails" level={2}>
81-
Dotenv‑Rails and Early Boot Logs
82-
</HeadingWithAnchor>
83-
<p className="text-neutral-600 dark:text-neutral-400">
84-
Some libraries (e.g., <code>dotenv-rails</code>) log very early during
85-
boot. LogStruct subscribes to those notifications immediately and
86-
buffers structured logs. After your initializers run, LogStruct decides
87-
which set to emit:
88-
</p>
89-
<ul className="list-disc list-inside space-y-2 text-neutral-600 dark:text-neutral-400">
90-
<li>
91-
<b>Enabled:</b> Emit structured JSON logs (for example, a dotenv{' '}
92-
<em>update</em> event) and suppress original replay.
93-
</li>
94-
<li>
95-
<b>Disabled:</b> Emit original <code>[dotenv]</code> lines and discard
96-
the structured buffer.
97-
</li>
98-
</ul>
99-
<Callout type="warning" className="mt-2">
100-
When you run a <code>rails runner</code> inside your test suite, it
101-
inherits <code>RAILS_ENV=test</code>. Dotenv may have already loaded{' '}
102-
<code>.env.test</code>, so nested runs might only show a single “Loaded
103-
…” line (no “Set …” update).
104-
</Callout>
105-
10680
<HeadingWithAnchor id="production-recommendations" level={2}>
10781
Production Recommendations
10882
</HeadingWithAnchor>
@@ -121,19 +95,6 @@ config.logger = ActiveSupport::TaggedLogging.new(logger)`}
12195
</li>
12296
</ul>
12397

124-
<HeadingWithAnchor id="quick-diagnostics" level={2}>
125-
Quick Diagnostics
126-
</HeadingWithAnchor>
127-
<CodeBlock language="bash">
128-
{`# Verify structured boot logs (dotenv) in test env
129-
LOGSTRUCT_ENABLED=true RAILS_LOG_TO_STDOUT=1 DISABLE_SPRING=1 RAILS_ENV=test \
130-
rails runner 'puts LogStruct.enabled?'
131-
132-
# Verify original dotenv lines when disabled
133-
LOGSTRUCT_ENABLED=false RAILS_LOG_TO_STDOUT=1 DISABLE_SPRING=1 RAILS_ENV=development \
134-
rails runner 'puts LogStruct.enabled?'`}
135-
</CodeBlock>
136-
13798
<EditPageLink />
13899
</div>
139100
);

site/lib/log-generation/log-generator.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,18 @@ export class LogGenerator extends RandomDataGenerator {
153153
case LogType.ACTIONMAILER: {
154154
switch (evt ?? this.sample([Event.Delivery, Event.Delivered])) {
155155
case Event.Delivered:
156-
return ActionMailer.ActionMailerDelivered.random(this).serialize();
156+
return ActionMailer.ActionMailerDelivered.random(this, {
157+
to: [this.randomEmail()],
158+
from: 'no-reply@example.com',
159+
subject: 'Welcome!',
160+
}).serialize();
157161
case Event.Delivery:
158162
default:
159-
return ActionMailer.ActionMailerDelivery.random(this).serialize();
163+
return ActionMailer.ActionMailerDelivery.random(this, {
164+
to: [this.randomEmail()],
165+
from: 'no-reply@example.com',
166+
subject: 'Welcome!',
167+
}).serialize();
160168
}
161169
}
162170

0 commit comments

Comments
 (0)