Skip to content

Commit 6a9ce23

Browse files
committed
Add imports to ingestion API java sample
1 parent 73a50f2 commit 6a9ce23

File tree

1 file changed

+46
-39
lines changed

1 file changed

+46
-39
lines changed

articles/azure-monitor/logs/tutorial-logs-ingestion-code.md

Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -283,53 +283,60 @@ The following sample code uses the [Azure Monitor Ingestion client library for J
283283
4. Replace the variables in the following sample code with values from your DCE and DCR. You may also want to replace the sample data with your own.
284284
285285
```java
286-
public static void main(String[] args) {
287-
288-
LogsIngestionClient client = new LogsIngestionClientBuilder()
289-
.endpoint("https://logs-ingestion-rzmk.eastus2-1.ingest.monitor.azure.com")
290-
.credential(new DefaultAzureCredentialBuilder().build())
291-
.buildClient();
292-
293-
List<Object> dataList = Arrays.asList(
294-
new Object() {
295-
OffsetDateTime time = OffsetDateTime.now();
296-
String computer = "Computer1";
297-
Object additionalContext = new Object() {
298-
String instanceName = "user4";
299-
String timeZone = "Pacific Time";
300-
int level = 4;
301-
String counterName = "AppMetric1";
302-
double counterValue = 15.3;
303-
};
304-
},
305-
new Object() {
306-
OffsetDateTime time = OffsetDateTime.now();
307-
String computer = "Computer2";
308-
Object additionalContext = new Object() {
309-
String instanceName = "user2";
310-
String timeZone = "Central Time";
311-
int level = 3;
312-
String counterName = "AppMetric2";
313-
double counterValue = 43.5;
314-
};
315-
});
286+
import com.azure.identity.DefaultAzureCredentialBuilder;
287+
import com.azure.monitor.ingestion.models.LogsUploadException;
288+
289+
import java.time.OffsetDateTime;
290+
import java.util.Arrays;
291+
import java.util.List;
292+
293+
public class LogsUploadSample {
294+
public static void main(String[] args) {
316295
317-
try {
318-
client.upload("dcr-00000000000000000000000000000000", "Custom-MyTableRawData", dataList);
319-
System.out.println("Logs uploaded successfully");
320-
} catch (LogsUploadException exception) {
321-
System.out.println("Failed to upload logs ");
322-
exception.getLogsUploadErrors()
323-
.forEach(httpError -> System.out.println(httpError.getMessage()));
296+
LogsIngestionClient client = new LogsIngestionClientBuilder()
297+
.endpoint("https://logs-ingestion-rzmk.eastus2-1.ingest.monitor.azure.com")
298+
.credential(new DefaultAzureCredentialBuilder().build())
299+
.buildClient();
300+
301+
List<Object> dataList = Arrays.asList(
302+
new Object() {
303+
OffsetDateTime time = OffsetDateTime.now();
304+
String computer = "Computer1";
305+
Object additionalContext = new Object() {
306+
String instanceName = "user4";
307+
String timeZone = "Pacific Time";
308+
int level = 4;
309+
String counterName = "AppMetric1";
310+
double counterValue = 15.3;
311+
};
312+
},
313+
new Object() {
314+
OffsetDateTime time = OffsetDateTime.now();
315+
String computer = "Computer2";
316+
Object additionalContext = new Object() {
317+
String instanceName = "user2";
318+
String timeZone = "Central Time";
319+
int level = 3;
320+
String counterName = "AppMetric2";
321+
double counterValue = 43.5;
322+
};
323+
});
324+
325+
try {
326+
client.upload("dcr-00000000000000000000000000000000", "Custom-MyTableRawData", dataList);
327+
System.out.println("Logs uploaded successfully");
328+
} catch (LogsUploadException exception) {
329+
System.out.println("Failed to upload logs ");
330+
exception.getLogsUploadErrors()
331+
.forEach(httpError -> System.out.println(httpError.getMessage()));
324332
}
325333
}
334+
}
326335
```
327336
328337
5. Execute the code, and the data should arrive in your Log Analytics workspace within a few minutes.
329338
330339
331-
332-
333340
## [.NET](#tab/net)
334341
335342
The following script uses the [Azure Monitor Ingestion client library for .NET](/dotnet/api/overview/azure/Monitor.Ingestion-readme).

0 commit comments

Comments
 (0)