Skip to content

Commit 4da8bfd

Browse files
authored
[applicationinsights] Update applicationinsights to use snippets (#32500)
### Packages impacted by this PR - @azure/arm-applicationinsights ### Issues associated with this PR - #32416 ### Describe the problem that is addressed by this PR Updates all projects under the `applicationinsights` to use snippets extraction. ### What are the possible designs available to address the problem? If there are more than one possible design, why was the one in this PR chosen? ### Are there test cases added in this PR? _(If not, why?)_ ### Provide a list of related PRs _(if any)_ ### Command used to generate this PR:**_(Applicable only to SDK release request PRs)_ ### Checklists - [ ] Added impacted package name to the issue description - [ ] Does this PR needs any fixes in the SDK Generator?** _(If so, create an Issue in the [Autorest/typescript](https://github.com/Azure/autorest.typescript) repository and link it here)_ - [ ] Added a changelog (if necessary)
1 parent 9ce5139 commit 4da8bfd

File tree

5 files changed

+70
-55
lines changed

5 files changed

+70
-55
lines changed

sdk/applicationinsights/arm-appinsights/LICENSE.txt

-21
This file was deleted.

sdk/applicationinsights/arm-appinsights/README.md

+21-12
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,31 @@ Set the values of the client ID, tenant ID, and client secret of the AAD applica
4848

4949
For more information about how to create an Azure AD Application check out [this guide](https://learn.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal).
5050

51-
```javascript
52-
const { ApplicationInsightsManagementClient } = require("@azure/arm-appinsights");
53-
const { DefaultAzureCredential } = require("@azure/identity");
54-
// For client-side applications running in the browser, use InteractiveBrowserCredential instead of DefaultAzureCredential. See https://aka.ms/azsdk/js/identity/examples for more details.
51+
Using Node.js and Node-like environments, you can use the `DefaultAzureCredential` class to authenticate the client.
52+
53+
```ts snippet:ReadmeSampleCreateClient_Node
54+
import { ApplicationInsightsManagementClient } from "@azure/arm-appinsights";
55+
import { DefaultAzureCredential } from "@azure/identity";
5556

5657
const subscriptionId = "00000000-0000-0000-0000-000000000000";
5758
const client = new ApplicationInsightsManagementClient(
5859
new DefaultAzureCredential(),
5960
subscriptionId,
6061
);
62+
```
63+
64+
For browser environments, use the `InteractiveBrowserCredential` from the `@azure/identity` package to authenticate.
6165

62-
// For client-side applications running in the browser, use this code instead:
63-
// const credential = new InteractiveBrowserCredential({
64-
// tenantId: "<YOUR_TENANT_ID>",
65-
// clientId: "<YOUR_CLIENT_ID>"
66-
// });
67-
// const client = new ApplicationInsightsManagementClient(credential, subscriptionId);
66+
```ts snippet:ReadmeSampleCreateClient_Browser
67+
import { InteractiveBrowserCredential } from "@azure/identity";
68+
import { ApplicationInsightsManagementClient } from "@azure/arm-appinsights";
69+
70+
const subscriptionId = "00000000-0000-0000-0000-000000000000";
71+
const credential = new InteractiveBrowserCredential({
72+
tenantId: "<YOUR_TENANT_ID>",
73+
clientId: "<YOUR_CLIENT_ID>",
74+
});
75+
const client = new ApplicationInsightsManagementClient(credential, subscriptionId);
6876
```
6977

7078
### JavaScript Bundle
@@ -83,8 +91,9 @@ To use this client library in the browser, first you need to use a bundler. For
8391

8492
Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:
8593

86-
```javascript
87-
const { setLogLevel } = require("@azure/logger");
94+
```ts snippet:SetLogLevel
95+
import { setLogLevel } from "@azure/logger";
96+
8897
setLogLevel("info");
8998
```
9099

sdk/applicationinsights/arm-appinsights/package.json

+11-12
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,19 @@
88
"node": ">=18.0.0"
99
},
1010
"dependencies": {
11-
"@azure/core-auth": "^1.3.0",
12-
"@azure/core-client": "^1.6.1",
13-
"@azure/core-paging": "^1.2.0",
14-
"@azure/core-rest-pipeline": "^1.8.0",
15-
"tslib": "^2.2.0"
11+
"@azure/core-auth": "^1.9.0",
12+
"@azure/core-client": "^1.9.2",
13+
"@azure/core-paging": "^1.6.2",
14+
"@azure/core-rest-pipeline": "^1.18.1",
15+
"tslib": "^2.8.1"
1616
},
1717
"keywords": [
1818
"node",
1919
"azure",
2020
"typescript",
2121
"browser",
22-
"isomorphic"
22+
"isomorphic",
23+
"cloud"
2324
],
2425
"license": "MIT",
2526
"main": "./dist/commonjs/index.js",
@@ -30,7 +31,8 @@
3031
"@azure-tools/test-recorder": "^4.1.0",
3132
"@azure-tools/test-utils-vitest": "^1.0.0",
3233
"@azure/dev-tool": "^1.0.0",
33-
"@azure/identity": "^4.0.1",
34+
"@azure/identity": "^4.5.0",
35+
"@azure/logger": "^1.1.4",
3436
"@types/node": "^18.0.0",
3537
"@vitest/browser": "^2.1.8",
3638
"@vitest/coverage-istanbul": "^2.1.8",
@@ -39,10 +41,7 @@
3941
"vitest": "^2.1.8"
4042
},
4143
"homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/applicationinsights/arm-appinsights",
42-
"repository": {
43-
"type": "git",
44-
"url": "https://github.com/Azure/azure-sdk-for-js.git"
45-
},
44+
"repository": "github:Azure/azure-sdk-for-js",
4645
"bugs": {
4746
"url": "https://github.com/Azure/azure-sdk-for-js/issues"
4847
},
@@ -77,7 +76,7 @@
7776
"unit-test": "npm run unit-test:node && npm run unit-test:browser",
7877
"unit-test:browser": "echo skipped",
7978
"unit-test:node": "dev-tool run test:vitest",
80-
"update-snippets": "echo skipped"
79+
"update-snippets": "dev-tool run update-snippets"
8180
},
8281
"sideEffects": false,
8382
"//metadata": {

sdk/applicationinsights/arm-appinsights/test/sampleTest.spec.ts

+8-10
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,15 @@
66
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
77
*/
88

9-
import {
10-
Recorder,
11-
RecorderStartOptions
12-
} from "@azure-tools/test-recorder";
13-
import { afterEach, beforeEach, describe, it } from "vitest";
9+
import type { RecorderStartOptions } from "@azure-tools/test-recorder";
10+
import { Recorder } from "@azure-tools/test-recorder";
11+
import { afterEach, beforeEach, describe, it, assert } from "vitest";
1412

1513
const replaceableVariables: Record<string, string> = {
1614
AZURE_CLIENT_ID: "azure_client_id",
1715
AZURE_CLIENT_SECRET: "azure_client_secret",
1816
AZURE_TENANT_ID: "88888888-8888-8888-8888-888888888888",
19-
SUBSCRIPTION_ID: "azure_subscription_id"
17+
SUBSCRIPTION_ID: "azure_subscription_id",
2018
};
2119

2220
const recorderOptions: RecorderStartOptions = {
@@ -30,16 +28,16 @@ const recorderOptions: RecorderStartOptions = {
3028
describe("My test", () => {
3129
let recorder: Recorder;
3230

33-
beforeEach(async function (ctx) {
31+
beforeEach(async (ctx) => {
3432
recorder = new Recorder(ctx);
3533
await recorder.start(recorderOptions);
3634
});
3735

38-
afterEach(async function () {
36+
afterEach(async () => {
3937
await recorder.stop();
4038
});
4139

42-
it("sample test", async function () {
43-
console.log("Hi, I'm a test!");
40+
it("sample test", async () => {
41+
assert(true);
4442
});
4543
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
import { ApplicationInsightsManagementClient } from "../src/index.js";
5+
import { DefaultAzureCredential, InteractiveBrowserCredential } from "@azure/identity";
6+
import { setLogLevel } from "@azure/logger";
7+
import { describe, it } from "vitest";
8+
9+
describe("snippets", () => {
10+
it("ReadmeSampleCreateClient_Node", async () => {
11+
const subscriptionId = "00000000-0000-0000-0000-000000000000";
12+
const client = new ApplicationInsightsManagementClient(
13+
new DefaultAzureCredential(),
14+
subscriptionId,
15+
);
16+
});
17+
18+
it("ReadmeSampleCreateClient_Browser", async () => {
19+
const subscriptionId = "00000000-0000-0000-0000-000000000000";
20+
const credential = new InteractiveBrowserCredential({
21+
tenantId: "<YOUR_TENANT_ID>",
22+
clientId: "<YOUR_CLIENT_ID>",
23+
});
24+
const client = new ApplicationInsightsManagementClient(credential, subscriptionId);
25+
});
26+
27+
it("SetLogLevel", async () => {
28+
setLogLevel("info");
29+
});
30+
});

0 commit comments

Comments
 (0)