@@ -2,8 +2,10 @@ import {
22 AsyncIterableStream ,
33 createAsyncIterableStreamFromAsyncIterable ,
44 SemanticInternalAttributes ,
5+ taskContext ,
56} from "@trigger.dev/core/v3" ;
67import { logger } from "@trigger.dev/sdk/v3" ;
8+ import { carrierFromContext } from "@trigger.dev/core/v3/otel" ;
79import assert from "node:assert" ;
810import fs from "node:fs" ;
911import { Result , x , Options as XOptions } from "tinyexec" ;
@@ -17,6 +19,8 @@ export const python = {
1719 async run ( scriptArgs : string [ ] = [ ] , options : PythonExecOptions = { } ) : Promise < Result > {
1820 const pythonBin = process . env . PYTHON_BIN_PATH || "python" ;
1921
22+ const carrier = carrierFromContext ( ) ;
23+
2024 return await logger . trace (
2125 "python.run()" ,
2226 async ( span ) => {
@@ -27,6 +31,12 @@ export const python = {
2731 env : {
2832 ...process . env ,
2933 ...options . env ,
34+ TRACEPARENT : carrier [ "traceparent" ] ,
35+ OTEL_RESOURCE_ATTRIBUTES : `${
36+ SemanticInternalAttributes . EXECUTION_ENVIRONMENT
37+ } =trigger,${ Object . entries ( taskContext . attributes )
38+ . map ( ( [ key , value ] ) => `${ key } =${ value } ` )
39+ . join ( "," ) } `,
3040 } ,
3141 } ,
3242 throwOnError : false , // Ensure errors are handled manually
@@ -50,7 +60,7 @@ export const python = {
5060 attributes : {
5161 pythonBin,
5262 args : scriptArgs . join ( " " ) ,
53- [ SemanticInternalAttributes . STYLE_ICON ] : "brand- python" ,
63+ [ SemanticInternalAttributes . STYLE_ICON ] : "python" ,
5464 } ,
5565 }
5666 ) ;
@@ -69,6 +79,8 @@ export const python = {
6979 async ( span ) => {
7080 span . setAttribute ( "scriptPath" , scriptPath ) ;
7181
82+ const carrier = carrierFromContext ( ) ;
83+
7284 const result = await x (
7385 process . env . PYTHON_BIN_PATH || "python" ,
7486 [ scriptPath , ...scriptArgs ] ,
@@ -79,6 +91,13 @@ export const python = {
7991 env : {
8092 ...process . env ,
8193 ...options . env ,
94+ TRACEPARENT : carrier [ "traceparent" ] ,
95+ OTEL_RESOURCE_ATTRIBUTES : `${
96+ SemanticInternalAttributes . EXECUTION_ENVIRONMENT
97+ } =trigger,${ Object . entries ( taskContext . attributes )
98+ . map ( ( [ key , value ] ) => `${ key } =${ value } ` )
99+ . join ( "," ) } `,
100+ OTEL_LOG_LEVEL : "DEBUG" ,
82101 } ,
83102 } ,
84103 throwOnError : false ,
@@ -93,7 +112,7 @@ export const python = {
93112 throw new Error (
94113 `${ scriptPath } ${ scriptArgs . join ( " " ) } exited with a non-zero code ${
95114 result . exitCode
96- } :\n${ result . stderr } `
115+ } :\n${ result . stdout } \n ${ result . stderr } `
97116 ) ;
98117 }
99118
@@ -104,7 +123,7 @@ export const python = {
104123 pythonBin : process . env . PYTHON_BIN_PATH || "python" ,
105124 scriptPath,
106125 args : scriptArgs . join ( " " ) ,
107- [ SemanticInternalAttributes . STYLE_ICON ] : "brand- python" ,
126+ [ SemanticInternalAttributes . STYLE_ICON ] : "python" ,
108127 } ,
109128 }
110129 ) ;
@@ -124,6 +143,8 @@ export const python = {
124143 async ( tempFilePath ) => {
125144 span . setAttribute ( "tempFilePath" , tempFilePath ) ;
126145
146+ const carrier = carrierFromContext ( ) ;
147+
127148 const pythonBin = process . env . PYTHON_BIN_PATH || "python" ;
128149 const result = await x ( pythonBin , [ tempFilePath ] , {
129150 ...options ,
@@ -132,6 +153,12 @@ export const python = {
132153 env : {
133154 ...process . env ,
134155 ...options . env ,
156+ TRACEPARENT : carrier [ "traceparent" ] ,
157+ OTEL_RESOURCE_ATTRIBUTES : `${
158+ SemanticInternalAttributes . EXECUTION_ENVIRONMENT
159+ } =trigger,${ Object . entries ( taskContext . attributes )
160+ . map ( ( [ key , value ] ) => `${ key } =${ value } ` )
161+ . join ( "," ) } `,
135162 } ,
136163 } ,
137164 throwOnError : false ,
@@ -157,7 +184,7 @@ export const python = {
157184 pythonBin : process . env . PYTHON_BIN_PATH || "python" ,
158185 contentPreview :
159186 scriptContent . substring ( 0 , 100 ) + ( scriptContent . length > 100 ? "..." : "" ) ,
160- [ SemanticInternalAttributes . STYLE_ICON ] : "brand- python" ,
187+ [ SemanticInternalAttributes . STYLE_ICON ] : "python" ,
161188 } ,
162189 }
163190 ) ;
@@ -167,13 +194,21 @@ export const python = {
167194 run ( scriptArgs : string [ ] = [ ] , options : PythonExecOptions = { } ) : AsyncIterableStream < string > {
168195 const pythonBin = process . env . PYTHON_BIN_PATH || "python" ;
169196
197+ const carrier = carrierFromContext ( ) ;
198+
170199 const pythonProcess = x ( pythonBin , scriptArgs , {
171200 ...options ,
172201 nodeOptions : {
173202 ...( options . nodeOptions || { } ) ,
174203 env : {
175204 ...process . env ,
176205 ...options . env ,
206+ TRACEPARENT : carrier [ "traceparent" ] ,
207+ OTEL_RESOURCE_ATTRIBUTES : `${
208+ SemanticInternalAttributes . EXECUTION_ENVIRONMENT
209+ } =trigger,${ Object . entries ( taskContext . attributes )
210+ . map ( ( [ key , value ] ) => `${ key } =${ value } ` )
211+ . join ( "," ) } `,
177212 } ,
178213 } ,
179214 throwOnError : false ,
@@ -183,7 +218,7 @@ export const python = {
183218 attributes : {
184219 pythonBin,
185220 args : scriptArgs . join ( " " ) ,
186- [ SemanticInternalAttributes . STYLE_ICON ] : "brand- python" ,
221+ [ SemanticInternalAttributes . STYLE_ICON ] : "python" ,
187222 } ,
188223 } ) ;
189224
@@ -206,13 +241,21 @@ export const python = {
206241
207242 const pythonBin = process . env . PYTHON_BIN_PATH || "python" ;
208243
244+ const carrier = carrierFromContext ( ) ;
245+
209246 const pythonProcess = x ( pythonBin , [ scriptPath , ...scriptArgs ] , {
210247 ...options ,
211248 nodeOptions : {
212249 ...( options . nodeOptions || { } ) ,
213250 env : {
214251 ...process . env ,
215252 ...options . env ,
253+ TRACEPARENT : carrier [ "traceparent" ] ,
254+ OTEL_RESOURCE_ATTRIBUTES : `${
255+ SemanticInternalAttributes . EXECUTION_ENVIRONMENT
256+ } =trigger,${ Object . entries ( taskContext . attributes )
257+ . map ( ( [ key , value ] ) => `${ key } =${ value } ` )
258+ . join ( "," ) } `,
216259 } ,
217260 } ,
218261 throwOnError : false ,
@@ -223,7 +266,7 @@ export const python = {
223266 pythonBin,
224267 scriptPath,
225268 args : scriptArgs . join ( " " ) ,
226- [ SemanticInternalAttributes . STYLE_ICON ] : "brand- python" ,
269+ [ SemanticInternalAttributes . STYLE_ICON ] : "python" ,
227270 } ,
228271 } ) ;
229272
@@ -243,13 +286,21 @@ export const python = {
243286
244287 const pythonScriptPath = createTempFileSync ( `script_${ Date . now ( ) } .py` , scriptContent ) ;
245288
289+ const carrier = carrierFromContext ( ) ;
290+
246291 const pythonProcess = x ( pythonBin , [ pythonScriptPath ] , {
247292 ...options ,
248293 nodeOptions : {
249294 ...( options . nodeOptions || { } ) ,
250295 env : {
251296 ...process . env ,
252297 ...options . env ,
298+ TRACEPARENT : carrier [ "traceparent" ] ,
299+ OTEL_RESOURCE_ATTRIBUTES : `${
300+ SemanticInternalAttributes . EXECUTION_ENVIRONMENT
301+ } =trigger,${ Object . entries ( taskContext . attributes )
302+ . map ( ( [ key , value ] ) => `${ key } =${ value } ` )
303+ . join ( "," ) } `,
253304 } ,
254305 } ,
255306 throwOnError : false ,
@@ -260,7 +311,7 @@ export const python = {
260311 pythonBin,
261312 contentPreview :
262313 scriptContent . substring ( 0 , 100 ) + ( scriptContent . length > 100 ? "..." : "" ) ,
263- [ SemanticInternalAttributes . STYLE_ICON ] : "brand- python" ,
314+ [ SemanticInternalAttributes . STYLE_ICON ] : "python" ,
264315 } ,
265316 } ) ;
266317
0 commit comments