Skip to content

Commit

Permalink
chore(detectors/node): adapted breaking change in @opentelemetry/sdk-…
Browse files Browse the repository at this point in the history
…node@0.37.0

- open-telemetry/opentelemetry-js#3460
- Deprecated detectResources() in favor of a new method detectResourcesSync() which defers promises into the resource to be resolved later
- introduced await resource.waitForAsyncAttributes?.();
  • Loading branch information
kirrg001 committed Apr 12, 2023
1 parent 27943f4 commit 8bfbd76
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ const sdk = new NodeSDK({
resource: globalResource,
});

(async () => {
await sdk.detectResources();
sdk.start()

await sdk.start();
(async () => {
const resource = sdk["_resource"];
await resource.waitForAsyncAttributes?.();
}());
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"devDependencies": {
"@opentelemetry/api": "^1.3.0",
"@opentelemetry/contrib-test-utils": "^0.33.1",
"@opentelemetry/sdk-node": "^0.35.1",
"@opentelemetry/sdk-node": "^0.37.0",
"@types/mocha": "8.2.3",
"@types/node": "18.11.7",
"@types/semver": "7.3.8",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Detector, Resource } from '@opentelemetry/resources';
import { Detector, Resource, IResource } from '@opentelemetry/resources';
import { diag } from '@opentelemetry/api';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import * as http from 'http';
Expand All @@ -22,7 +22,7 @@ class InstanaAgentDetector implements Detector {
readonly INSTANA_AGENT_DEFAULT_HOST = 'localhost';
readonly INSTANA_AGENT_DEFAULT_PORT = 42699;

async detect(): Promise<Resource> {
async detect(): Promise<IResource> {
const host =
process.env.INSTANA_AGENT_HOST || this.INSTANA_AGENT_DEFAULT_HOST;
const port = Number(
Expand Down Expand Up @@ -112,7 +112,6 @@ class InstanaAgentDetector implements Detector {

try {
const data = JSON.parse(rawData);

if (data.pid && data.agentUuid) {
return resolve(data);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@ describe('[Integration] instanaAgentDetector', () => {
resource: globalResource,
});

// attributes are automatically merged!
await sdk.detectResources();
sdk.detectResources();

const resource = sdk['_resource'];
// await sdk.detectResources(); [< @opentelemetry/sdk-node@0.37.0]
// await resource.waitForAsyncAttributes?.(); [>= @opentelemetry/sdk-node@0.37.0]
await resource.waitForAsyncAttributes?.();

assert.equal(resource.attributes['process.pid'], 123);
assert.equal(resource.attributes['process.runtime.name'], 'nodejs');
Expand Down

0 comments on commit 8bfbd76

Please sign in to comment.