Skip to content

Commit 99f9214

Browse files
committed
Add example of end-to-end tracing
1 parent 8d32964 commit 99f9214

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

examples/endtoend.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
2+
3+
/******************************************************************************
4+
*
5+
* You may not use the identified files except in compliance with the Apache
6+
* License, Version 2.0 (the "License.")
7+
*
8+
* You may obtain a copy of the License at
9+
* http://www.apache.org/licenses/LICENSE-2.0.
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
*
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* NAME
19+
* endtoend.js
20+
*
21+
* DESCRIPTION
22+
* Show setting connection metadata for end-to-end tracing and client authorization.
23+
* While the script sleeps (keeping the connection open), use SQL*Plus as SYSTEM to execute:
24+
* SELECT username, client_identifier, action, module FROM v$session WHERE username IS NOT NULL;
25+
* The end-to-end tracing attributes are shown in various other DBA views and in Enterprise Manager.
26+
*
27+
*****************************************************************************/
28+
29+
var oracledb = require('oracledb');
30+
var dbConfig = require('./dbconfig.js');
31+
32+
oracledb.getConnection(
33+
{
34+
user : dbConfig.user,
35+
password : dbConfig.password,
36+
connectString : dbConfig.connectString
37+
},
38+
function(err, connection)
39+
{
40+
if (err) { console.error(err.message); return; }
41+
42+
// These end-to-end tracing attributes are sent to the database on
43+
// the next 'round trip' i.e. with execute()
44+
connection.clientId = "Chris";
45+
connection.module = "End-to-end example";
46+
connection.action = "Query departments";
47+
48+
connection.execute("SELECT * FROM dual",
49+
function(err, result)
50+
{
51+
if (err) { doRelease(connection); console.error(err.message); return; }
52+
console.log(result.rows);
53+
// Sleep 10 seconds to keep the connection open. This allows
54+
// external queries on V$SESSION to show the connection
55+
// attributes.
56+
console.log('Use SQL*Plus as SYSTEM to execute:');
57+
console.log('SELECT username, client_identifier, action, module FROM v$session WHERE username IS NOT NULL;');
58+
sleep(10000);
59+
doRelease(connection);
60+
});
61+
});
62+
63+
// Sleep for t milliseconds
64+
function sleep(t) {
65+
var start = new Date().getTime();
66+
while(new Date().getTime() < start + t) {
67+
; // empty
68+
}
69+
}
70+
71+
// Release the connection
72+
function doRelease(connection)
73+
{
74+
connection.release(
75+
function(err) {
76+
if (err) {
77+
console.error(err.message);
78+
}
79+
});
80+
}

0 commit comments

Comments
 (0)