You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/azure-functions/functions-reference-python.md
+23Lines changed: 23 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -517,6 +517,28 @@ More logging methods are available that let you write to the console at differen
517
517
518
518
To learn more about logging, see [Monitor Azure Functions](functions-monitoring.md).
519
519
520
+
### Logging from created threads
521
+
522
+
To see logs coming from your created threads, include the [`context`](/python/api/azure-functions/azure.functions.context) argument in the function's signature. This argument contains an attribute `thread_local_storage` which stores a local `invocation_id`. This can be set to the function's current `invocation_id` to ensure the context is changed.
523
+
524
+
```python
525
+
import azure.functions as func
526
+
import logging
527
+
import threading
528
+
529
+
530
+
defmain(req, context):
531
+
logging.info('Python HTTP trigger function processed a request.')
532
+
t = threading.Thread(target=log_function, args=(context,))
By default, the Functions runtime collects logs and other telemetry data that are generated by your functions. This telemetry ends up as traces in Application Insights. Request and dependency telemetry for certain Azure services are also collected by default by [triggers and bindings](functions-triggers-bindings.md#supported-bindings).
@@ -850,6 +872,7 @@ The [`Context`](/python/api/azure-functions/azure.functions.context) class has t
850
872
|`function_directory`| The directory in which the function is running. |
851
873
|`function_name`| The name of the function. |
852
874
|`invocation_id`| The ID of the current function invocation. |
875
+
|`thread_local_storage`| The thread local storage of the function. Contains a local `invocation_id` for [logging from created threads](#logging-from-created-threads). |
853
876
|`trace_context`| The context for distributed tracing. For more information, see [`Trace Context`](https://www.w3.org/TR/trace-context/). |
854
877
|`retry_context`| The context for retries to the function. For more information, see [`retry-policies`](./functions-bindings-errors.md#retry-policies). |
0 commit comments