@@ -49,10 +49,27 @@ public function __construct(
4949 *
5050 * @param string $body The log message
5151 * @param Attributes|TAttributeValueMap $attributes Optional attributes
52+ * @param null|\DateTimeImmutable $timestamp When the event occurred (defaults to current time)
53+ * @param null|\DateTimeImmutable $observedTimestamp When the log was observed by collection
54+ * @param null|SpanContext $spanContext Span context for trace correlation (defaults to current active span)
5255 */
53- public function debug (string $ body , array |Attributes $ attributes = []) : void
54- {
55- $ this ->emit (new LogRecord (Severity::DEBUG , $ body , $ attributes instanceof Attributes ? $ attributes : Attributes::create ($ attributes )));
56+ public function debug (
57+ string $ body ,
58+ array |Attributes $ attributes = [],
59+ ?\DateTimeImmutable $ timestamp = null ,
60+ ?\DateTimeImmutable $ observedTimestamp = null ,
61+ ?SpanContext $ spanContext = null ,
62+ ) : void {
63+ $ this ->emit (
64+ new LogRecord (
65+ Severity::DEBUG ,
66+ $ body ,
67+ $ attributes instanceof Attributes ? $ attributes : Attributes::create ($ attributes ),
68+ $ timestamp ,
69+ $ observedTimestamp ,
70+ ),
71+ $ spanContext ,
72+ );
5673 }
5774
5875 /**
@@ -62,15 +79,16 @@ public function debug(string $body, array|Attributes $attributes = []) : void
6279 * such as setting a custom timestamp or recording an exception.
6380 *
6481 * @param LogRecord $record The log record to emit
82+ * @param null|SpanContext $spanContext Span context for trace correlation (defaults to current active span)
6583 */
66- public function emit (LogRecord $ record ) : void
84+ public function emit (LogRecord $ record, ? SpanContext $ spanContext = null ) : void
6785 {
6886 $ entry = new LogEntry (
6987 $ record ,
7088 $ this ->resource ,
7189 $ this ->scope ,
7290 $ record ->timestamp ?? $ this ->clock ->now (),
73- $ this ->resolveSpanContext (),
91+ $ spanContext ?? $ this ->resolveSpanContext (),
7492 );
7593
7694 $ this ->processor ->process ($ entry );
@@ -84,10 +102,27 @@ public function emit(LogRecord $record) : void
84102 *
85103 * @param string $body The log message
86104 * @param Attributes|TAttributeValueMap $attributes Optional attributes
105+ * @param null|\DateTimeImmutable $timestamp When the event occurred (defaults to current time)
106+ * @param null|\DateTimeImmutable $observedTimestamp When the log was observed by collection
107+ * @param null|SpanContext $spanContext Span context for trace correlation (defaults to current active span)
87108 */
88- public function error (string $ body , array |Attributes $ attributes = []) : void
89- {
90- $ this ->emit (new LogRecord (Severity::ERROR , $ body , $ attributes instanceof Attributes ? $ attributes : Attributes::create ($ attributes )));
109+ public function error (
110+ string $ body ,
111+ array |Attributes $ attributes = [],
112+ ?\DateTimeImmutable $ timestamp = null ,
113+ ?\DateTimeImmutable $ observedTimestamp = null ,
114+ ?SpanContext $ spanContext = null ,
115+ ) : void {
116+ $ this ->emit (
117+ new LogRecord (
118+ Severity::ERROR ,
119+ $ body ,
120+ $ attributes instanceof Attributes ? $ attributes : Attributes::create ($ attributes ),
121+ $ timestamp ,
122+ $ observedTimestamp ,
123+ ),
124+ $ spanContext ,
125+ );
91126 }
92127
93128 /**
@@ -98,10 +133,27 @@ public function error(string $body, array|Attributes $attributes = []) : void
98133 *
99134 * @param string $body The log message
100135 * @param Attributes|TAttributeValueMap $attributes Optional attributes
136+ * @param null|\DateTimeImmutable $timestamp When the event occurred (defaults to current time)
137+ * @param null|\DateTimeImmutable $observedTimestamp When the log was observed by collection
138+ * @param null|SpanContext $spanContext Span context for trace correlation (defaults to current active span)
101139 */
102- public function fatal (string $ body , array |Attributes $ attributes = []) : void
103- {
104- $ this ->emit (new LogRecord (Severity::FATAL , $ body , $ attributes instanceof Attributes ? $ attributes : Attributes::create ($ attributes )));
140+ public function fatal (
141+ string $ body ,
142+ array |Attributes $ attributes = [],
143+ ?\DateTimeImmutable $ timestamp = null ,
144+ ?\DateTimeImmutable $ observedTimestamp = null ,
145+ ?SpanContext $ spanContext = null ,
146+ ) : void {
147+ $ this ->emit (
148+ new LogRecord (
149+ Severity::FATAL ,
150+ $ body ,
151+ $ attributes instanceof Attributes ? $ attributes : Attributes::create ($ attributes ),
152+ $ timestamp ,
153+ $ observedTimestamp ,
154+ ),
155+ $ spanContext ,
156+ );
105157 }
106158
107159 /**
@@ -120,10 +172,27 @@ public function flush() : bool
120172 *
121173 * @param string $body The log message
122174 * @param Attributes|TAttributeValueMap $attributes Optional attributes
175+ * @param null|\DateTimeImmutable $timestamp When the event occurred (defaults to current time)
176+ * @param null|\DateTimeImmutable $observedTimestamp When the log was observed by collection
177+ * @param null|SpanContext $spanContext Span context for trace correlation (defaults to current active span)
123178 */
124- public function info (string $ body , array |Attributes $ attributes = []) : void
125- {
126- $ this ->emit (new LogRecord (Severity::INFO , $ body , $ attributes instanceof Attributes ? $ attributes : Attributes::create ($ attributes )));
179+ public function info (
180+ string $ body ,
181+ array |Attributes $ attributes = [],
182+ ?\DateTimeImmutable $ timestamp = null ,
183+ ?\DateTimeImmutable $ observedTimestamp = null ,
184+ ?SpanContext $ spanContext = null ,
185+ ) : void {
186+ $ this ->emit (
187+ new LogRecord (
188+ Severity::INFO ,
189+ $ body ,
190+ $ attributes instanceof Attributes ? $ attributes : Attributes::create ($ attributes ),
191+ $ timestamp ,
192+ $ observedTimestamp ,
193+ ),
194+ $ spanContext ,
195+ );
127196 }
128197
129198 /**
@@ -150,10 +219,27 @@ public function processor() : LogProcessor
150219 *
151220 * @param string $body The log message
152221 * @param Attributes|TAttributeValueMap $attributes Optional attributes
222+ * @param null|\DateTimeImmutable $timestamp When the event occurred (defaults to current time)
223+ * @param null|\DateTimeImmutable $observedTimestamp When the log was observed by collection
224+ * @param null|SpanContext $spanContext Span context for trace correlation (defaults to current active span)
153225 */
154- public function trace (string $ body , array |Attributes $ attributes = []) : void
155- {
156- $ this ->emit (new LogRecord (Severity::TRACE , $ body , $ attributes instanceof Attributes ? $ attributes : Attributes::create ($ attributes )));
226+ public function trace (
227+ string $ body ,
228+ array |Attributes $ attributes = [],
229+ ?\DateTimeImmutable $ timestamp = null ,
230+ ?\DateTimeImmutable $ observedTimestamp = null ,
231+ ?SpanContext $ spanContext = null ,
232+ ) : void {
233+ $ this ->emit (
234+ new LogRecord (
235+ Severity::TRACE ,
236+ $ body ,
237+ $ attributes instanceof Attributes ? $ attributes : Attributes::create ($ attributes ),
238+ $ timestamp ,
239+ $ observedTimestamp ,
240+ ),
241+ $ spanContext ,
242+ );
157243 }
158244
159245 /**
@@ -163,11 +249,28 @@ public function trace(string $body, array|Attributes $attributes = []) : void
163249 * the application from functioning.
164250 *
165251 * @param string $body The log message
166- * @param array<string, array<bool|float|int|string>|bool|float|int|string>|Attributes $attributes Optional attributes
252+ * @param Attributes|TAttributeValueMap $attributes Optional attributes
253+ * @param null|\DateTimeImmutable $timestamp When the event occurred (defaults to current time)
254+ * @param null|\DateTimeImmutable $observedTimestamp When the log was observed by collection
255+ * @param null|SpanContext $spanContext Span context for trace correlation (defaults to current active span)
167256 */
168- public function warn (string $ body , array |Attributes $ attributes = []) : void
169- {
170- $ this ->emit (new LogRecord (Severity::WARN , $ body , $ attributes instanceof Attributes ? $ attributes : Attributes::create ($ attributes )));
257+ public function warn (
258+ string $ body ,
259+ array |Attributes $ attributes = [],
260+ ?\DateTimeImmutable $ timestamp = null ,
261+ ?\DateTimeImmutable $ observedTimestamp = null ,
262+ ?SpanContext $ spanContext = null ,
263+ ) : void {
264+ $ this ->emit (
265+ new LogRecord (
266+ Severity::WARN ,
267+ $ body ,
268+ $ attributes instanceof Attributes ? $ attributes : Attributes::create ($ attributes ),
269+ $ timestamp ,
270+ $ observedTimestamp ,
271+ ),
272+ $ spanContext ,
273+ );
171274 }
172275
173276 /**
0 commit comments