Skip to content

Commit f5f729e

Browse files
committed
update doc2
1 parent fe0f628 commit f5f729e

File tree

2 files changed

+33
-13
lines changed

2 files changed

+33
-13
lines changed

articles/synapse-analytics/spark/how-to-use-certsp-emit-log-to-eventhub.md

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@ ms.date: 03/24/2025
2525
> To complete this tutorial's steps, you need to have access to a resource group for which you're assigned the Owner role.
2626
>
2727
28-
## Step 1. Create an App Registration (Service Principal)
28+
## Step 1. Register an application
2929

3030
1. Sign in to the [Azure portal](https://portal.azure.com/) and go to [App registrations](/entra/identity-platform/quickstart-register-app#register-an-application).
31-
2. Create a new app registration (Service Principal) for your Synapse workspace.
31+
2. Create a new app registration for your Synapse workspace.
3232

3333
:::image type="content" source="media\how-to-use-certsp-emit-log-to-eventhub\create-a-new-app-registration.png" alt-text="Screenshot showing create a new app registration.":::
3434

3535
## Step 2. Generate a Certificate in Key Vault
3636

3737
1. Navigate to Key Vault.
38-
2. Expand the **Odject**, and select the **Certificates**.
38+
2. Expand the **Object**, and select the **Certificates**.
3939
3. Click on **Generate/Import**.
4040

4141
:::image type="content" source="media\how-to-use-certsp-emit-log-to-eventhub\generate-a-new-certificate.png" alt-text="Screenshot showing generate a new certificate for app.":::
@@ -73,11 +73,12 @@ ms.date: 03/24/2025
7373
7474
## Step 6. Assign Reader Role to Linked Service in Key Vault
7575
76-
1. In **Key Vault**, assign the linked service a **Reader** role.
77-
2. You can find the linked service's managed identity name and object ID under **Edit linked service**.
76+
1. Get the workspace managed identity ID from the linked service. The **managed identity name** and **object ID** for the linked service is under **Edit Linked Service**.
7877
7978
:::image type="content" source="media\how-to-use-certsp-emit-log-to-eventhub\managed-identity-name-and-object-id.png" alt-text="Screenshot showing managed identity name and object id are in edit linked service.":::
8079
80+
2. In **Key Vault**, assign the linked service a **Reader** role.
81+
8182
## Step 7. Configure Logging in Synapse Notebook
8283
8384
1. Open your Synapse workspace and create or open a notebook.
@@ -111,16 +112,35 @@ ms.date: 03/24/2025
111112
- **EventHub.clientId**: App registrations -> your app name -> Overview -> Application(client) ID
112113
- **EventHub.entityPath**: Event Hubs Instance -> Settings -> Shared access policies -> Find "EntityPath" in Connection string
113114
114-
## Step 8. Run the Log-Sending Code
115+
## Step 8. Submit an Apache Spark application and view the logs and metrics
115116
116-
After executing the configuration code in Step 7, run the log-sending code to start emitting logs to Event Hub.
117+
You can use the Apache Log4j library to write custom logs.
117118
118-
```
119+
Example for Scala:
120+
121+
```scala
119122
%%spark
120-
val logger = org.apache.log4j.LogManager.getLogger("com.contoso.LoggerExample")
121-
logger.info("Hello, info message")
122-
logger.warn("Hello, warn message")
123-
logger.error("Hello, error message")
123+
val logger = org.apache.log4j.LogManager.getLogger("com.contoso.LoggerExample")
124+
logger.info("info message")
125+
logger.warn("warn message")
126+
logger.error("error message")
127+
//log exception
128+
try {
129+
1/0
130+
} catch {
131+
case e:Exception =>logger.warn("Exception", e)
132+
}
133+
// run job for task level metrics
134+
val data = sc.parallelize(Seq(1,2,3,4)).toDF().count()
124135
```
125136

137+
Example for PySpark:
138+
139+
```python
140+
%%pyspark
141+
logger = sc._jvm.org.apache.log4j.LogManager.getLogger("com.contoso.PythonLoggerExample")
142+
logger.info("info message")
143+
logger.warn("warn message")
144+
logger.error("error message")
145+
```
126146

articles/synapse-analytics/toc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ items:
820820
href: ./spark/apache-spark-azure-create-spark-configuration.md
821821
- name: Apache Spark Advisor
822822
href: ./monitoring/apache-spark-advisor.md
823-
- name: Use the certificate and service principal to send logs to EventHub
823+
- name: Collect Apache Spark applications logs and metrics by certificate and service principal
824824
href: ./spark/how-to-use-certsp-emit-log-to-eventhub.md
825825
- name: Data sources
826826
items:

0 commit comments

Comments
 (0)