|
12 | 12 | // See the License for the specific language governing permissions and |
13 | 13 | // limitations under the License. |
14 | 14 |
|
15 | | -#include <limits.h> |
16 | | -#include <unistd.h> |
17 | | -#include <cerrno> |
18 | 15 | #include <cstdlib> |
19 | | -#include <cstring> |
20 | 16 | #include <iostream> |
21 | 17 |
|
22 | | -#include "absl/strings/str_cat.h" |
23 | 18 | #include "examples/grpc/stackdriver.h" |
24 | 19 | #include "opencensus/exporters/stats/stackdriver/stackdriver_exporter.h" |
25 | 20 | #include "opencensus/exporters/trace/stackdriver/stackdriver_exporter.h" |
26 | 21 |
|
27 | | -// OS X defines _POSIX_HOST_NAME_MAX instead. |
28 | | -#ifndef HOST_NAME_MAX |
29 | | -#ifdef _POSIX_HOST_NAME_MAX |
30 | | -#define HOST_NAME_MAX _POSIX_HOST_NAME_MAX |
31 | | -#else |
32 | | -#define HOST_NAME_MAX 255 // SUSv2 says 255 is the limit. |
33 | | -#endif |
34 | | -#endif |
35 | | - |
36 | 22 | void RegisterStackdriverExporters() { |
37 | 23 | const char *project_id = getenv("STACKDRIVER_PROJECT_ID"); |
38 | 24 | if (project_id == nullptr) { |
39 | 25 | std::cerr << "The STACKDRIVER_PROJECT_ID environment variable is not set: " |
40 | 26 | "not exporting to Stackdriver.\n"; |
41 | 27 | return; |
42 | 28 | } |
43 | | - char hostname[HOST_NAME_MAX + 1]; |
44 | | - if (gethostname(hostname, sizeof(hostname)) == -1) { |
45 | | - std::cerr << "gethostname() failed: " << strerror(errno) << "\n"; |
46 | | - strncpy(hostname, "hostname", sizeof(hostname) - 1); |
47 | | - hostname[sizeof(hostname) - 1] = 0; |
48 | | - } |
| 29 | + |
| 30 | + std::cout << "RegisterStackdriverExporters:\n"; |
| 31 | + std::cout << " project_id = \"" << project_id << "\"\n"; |
49 | 32 |
|
50 | 33 | opencensus::exporters::stats::StackdriverOptions stats_opts; |
51 | 34 | stats_opts.project_id = project_id; |
52 | | - stats_opts.opencensus_task = absl::StrCat("cpp-", getpid(), "@", hostname); |
53 | | - |
54 | | - std::cout << "RegisterStackdriverExporters:\n"; |
55 | | - std::cout << " project_id = \"" << stats_opts.project_id << "\"\n"; |
56 | | - std::cout << " opencensus_task = \"" << stats_opts.opencensus_task << "\"\n"; |
| 35 | + opencensus::exporters::stats::StackdriverExporter::Register( |
| 36 | + std::move(stats_opts)); |
57 | 37 |
|
58 | 38 | opencensus::exporters::trace::StackdriverOptions trace_opts; |
59 | 39 | trace_opts.project_id = project_id; |
60 | | - |
61 | | - opencensus::exporters::stats::StackdriverExporter::Register( |
62 | | - std::move(stats_opts)); |
63 | 40 | opencensus::exporters::trace::StackdriverExporter::Register( |
64 | 41 | std::move(trace_opts)); |
65 | 42 | } |
0 commit comments